Skip to content

Instantly share code, notes, and snippets.

@Artur-Sulej
Last active December 3, 2015 01:22
Show Gist options
  • Save Artur-Sulej/03c5ae44a58454971344 to your computer and use it in GitHub Desktop.
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.
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