kirtan403
kirtan403

Reputation: 7411

Using string id for notification or converting string id to generate unique int id

In my app I have groups and for each group there can be updates which I am showing in notification. But in database I have group ids as string. So for generating notification for each group, I need a unique int id. So how can I transform string ids to int ids. So that there can be only 1 notification per group and the contents can be appended as there are updates in that specific group.

I have seen while displaying notifications I can supply tag as well.

NotificationManager.notify(String tag, int id, Notification notification)

But for that I also need to supply int id. So how this in combination works? Or any way I can rely only on the string id of the notification?

Upvotes: 1

Views: 1194

Answers (2)

Gaurav Chauhan
Gaurav Chauhan

Reputation: 376

Your (tag, id) combination of notifications to be shown differently should be different. Otherwise the latest one will replace the previous one. So, here you can just use the string id you have as tag if it is unique and use any int id as the combination must be unique.

Ref : (https://developer.android.com/reference/android/app/NotificationManager.html#notify(java.lang.String,%20int,%20android.app.Notification)

Upvotes: 3

Gabe Sechan
Gabe Sechan

Reputation: 93589

You can use the hash of the string. Or you can use the tag for a string.

Upvotes: 2

Related Questions