How to retain the global variebles when application is upgraded to new version in android?

后端 未结 3 664
遥遥无期
遥遥无期 2021-01-24 10:11

In my android application ,user has to register by agreeing the terms and condition giving their email id. If user upgrade the application to next version, I should not get the

3条回答
  •  北恋
    北恋 (楼主)
    2021-01-24 10:49

    You could use SharedPreferences

    class VersionInfo {
    
    private VersionInfo() {}
    
    private static final String PREF_VERCODE = "VERCODE";
    
    public static final VersionInfo INSTANCE = new VersionInfo();
    
    void setVersionCode(Context ctx, int ver) {
         PreferenceManager.getDefaultSharedPreferences(ctx).edit().putInt(PREF_VERCODE, ver).commit();
        }
    
    int getVersionInfo(Context ctx) {
    PreferenceManager.getDefaultSharedPreferences(ctx).getInt(PREF_VERCODE, 1);
    }
    }
    

提交回复
热议问题