How to delete shared preferences data from App in Android

前端 未结 24 2473
日久生厌
日久生厌 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:26

    To clear all SharedPreferences centrally from any class:

    public static SharedPreferences.Editor getEditor(Context context) {
        return getPreferences(context).edit();
    }
    

    And then from any class: (commit returns a Boolean where you can check whether your Preferences cleared or not)

    Navigation.getEditor(this).clear().commit();
    

    Or you can use apply; it returns void

    Navigation.getEditor(this).clear().apply();
    

提交回复
热议问题