简体   繁体   中英

how to keep randomUUID static

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();

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();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM