Shared Preferences reset data when app is force closed or device is restarted

后端 未结 6 1895
暖寄归人
暖寄归人 2020-11-30 11:21

I\'m developing an application in which I\'m storing username and password in SharedPreferences. All things are working fine for me, s

6条回答
  •  难免孤独
    2020-11-30 12:05

    See I have done like below.

            sharedPreferences = PreferenceManager
                    .getDefaultSharedPreferences(getApplicationContext());
            editor = sharedPreferences.edit();
            isPaidVerison = sharedPreferences.getInt("isPaidVerison", 0);
    
    
            editor.putInt("isPaidVerison", 1);
            editor.commit();
    

    And this works fine. Data will remain in Sharedprefrences till will do not reinstall the app or till will d'not clear data.

    And I retrive data this way.

           isPaidVerison = sharedPreferences.getInt("isPaidVerison", 0);
    

提交回复
热议问题