Last active
December 3, 2015 01:22
-
-
Save Artur-Sulej/03c5ae44a58454971344 to your computer and use it in GitHub Desktop.
Util class providing unique IDs - dead simple but helpful in case of for example PendingIntents in notifications.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Random; | |
public class UniqueIdUtility { | |
static private int id; | |
static { | |
id = Integer.MIN_VALUE + new Random().nextInt(Integer.MAX_VALUE); | |
} | |
static public int getId() { | |
int currentId = id; | |
if (id == Integer.MAX_VALUE) { | |
id = Integer.MIN_VALUE; | |
} else { | |
id += 1; | |
} | |
return currentId; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment