1

I generate the UUID but the problem is that when I close the app and run it again he generate another UUID, I want to generate UUID just for one time, and keep it always the same after installing the application.

private final static String androidId = UUID.randomUUID().toString(); 
4
  • 3
    You should save it to SharedPreference and check if it not generated will create new and store it Commented Jun 1, 2020 at 3:52
  • it is not posible is you turn off the app is running, since this variable is static but it belogs to the aplication running. you should persist Commented Jun 1, 2020 at 4:27
  • 1
    You don't mean 'static', you mean 'persistent'. It already is static. Commented Jun 1, 2020 at 4:56
  • @CôngHải thank you, It work . Commented Jun 1, 2020 at 11:37

1 Answer 1

1

reference to Công Hải's comment ,I used SharedPreference and it work perfectly:

private static String uuid; SharedPreferences sPrefs = PreferenceManager.getDefaultSharedPreferences(this); uuid = sPrefs.getString("uuid",null); if (uuid == null){ uuid = UUID.randomUUID().toString(); SharedPreferences.Editor editor = sPrefs.edit(); editor.putString("uuid",uuid); editor.apply(); } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.