how to reset all stored data store using shared preferences

前端 未结 4 1834
孤独总比滥情好
孤独总比滥情好 2021-01-01 15:29

I have created an activity where i have used shared preferences for storing data..now in another activity i have an reset button..when i click on the reset button the data s

相关标签:
4条回答
  • 2021-01-01 15:49

    Get your Editor and call clear() something like this: Edit: as the user DDoSAttack mentioned. There are two ways of getting SharedPreferences

    1: getting default SharedPreferences

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(con);
    

    2: getting specific SharedPreferences

    SharedPreferences prefs = Context.getSharedPreferences("FileName", Context.MODE_PRIVATE);
    

    and here is how you'll clear it.

    public void clear()
    {
         SharedPreferences prefs; // here you get your prefrences by either of two methods
         Editor editor = prefs.edit();
         editor.clear();
         editor.commit();
    }
    
    0 讨论(0)
  • 2021-01-01 15:51

    If you want to wipe all the data in a preference file call clear() from the SharedPreferences.Editor instance

    http://developer.android.com/reference/android/content/SharedPreferences.Editor.html#clear()

    0 讨论(0)
  • 2021-01-01 15:54

    its very easy..

    yourEditor.remove(" thing you want to remove on start");
    

    and then give must

    yourEditor.commit();
    
    0 讨论(0)
  • 2021-01-01 16:07

    Use SharedPreferences.Editor clear() method.

    See Documentation

    SharedPreferences preferences = getPreferences(0);
            SharedPreferences.Editor editor = preferences.edit();
    
            editor.clear();
            editor.commit();
    
    0 讨论(0)
提交回复
热议问题