How to delete shared preferences data from App in Android

前端 未结 24 2392
日久生厌
日久生厌 2020-11-22 14:37

How do I delete SharedPreferences data for my application?

I\'m creating an application that uses a lot of web services to sync data. For testing purposes, I need to

24条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-22 15:23

    Seems that all solution is not completely working or out-dead

    to clear all SharedPreferences in an Activity

    PreferenceManager.getDefaultSharedPreferences(getBaseContext()).edit().clear().apply();
    

    Call this from the Main Activity after onCreate

    note* i used .apply() instead of .commit(), you are free to choose commit();

提交回复
热议问题