kirtan403 kirtan403 - 23 days ago 8
Android Question

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?

Answer

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)