How to generate a unique ID in android

  • Replies:6
  • Answered
ASIF ALIYAR
  • Forum posts: 8

Mar 3, 2014, 8:28:05 AM via Website

Hi All. I have created an app for notification. in that i need to create a unique id for each notification. can anyone help me on how to create a unique id in android?

Reply
Pascal P.
  • Admin
  • Forum posts: 11,286

Mar 3, 2014, 8:53:55 AM via Website

What doey your app (functions)
Why do you need this unique id?
Where is the problem?
How does the notification code Looks like? (poste pls)

LG Pascal //It's not a bug, it's a feature. :) ;)

Reply
Pablo
  • Forum posts: 1

Mar 3, 2014, 8:57:32 AM via Website

You can use:
UUID.randomUUID()

Check the documentation for UUID class at the android developers documentation

Reply
ASIF ALIYAR
  • Forum posts: 8

Mar 3, 2014, 8:59:17 AM via Website

thanks for the reply pascal. if i need to set the more than one notification, i need to set the unique id of that.
notificationManager.notify(1, notification);

while doing this i was thinking about the unique id. since i am new in android, i am interested to know about the unique id generation.

Reply
Pascal P.
  • Admin
  • Forum posts: 11,286

Mar 3, 2014, 9:02:28 AM via Website

ok i understand.
Whats the Problem with it.
You have a interger i and every time when you Display a notification you do i+=1;
Then at runtime you have an unique id in every norification

LG Pascal //It's not a bug, it's a feature. :) ;)

Reply
ASIF ALIYAR
  • Forum posts: 8

Mar 4, 2014, 5:53:17 AM via Website

Thanks pascal. That works..

Reply
ASIF ALIYAR
  • Forum posts: 8

Mar 4, 2014, 6:03:40 AM via Website

thanks for the help and a new information Pablo. i have even tried UUID.randomUUID().hashCode();

Reply