How to delete shared preferences data from App in Android

前端 未结 24 2187
日久生厌
日久生厌 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:11
    Editor editor = getSharedPreferences("clear_cache", Context.MODE_PRIVATE).edit();
    editor.clear();
    editor.commit();
    
    0 讨论(0)
  • 2020-11-22 15:12

    If it's not necessary to be removed every time, you can remove it manually from:

    Settings -> Applications -> Manage applications -> (choose your app) -> Clear data or Uninstall

    Newer versions of Android:

    Settings -> Applications -> (choose your app) -> Storage -> Clear data and Clear cache

    0 讨论(0)
  • 2020-11-22 15:12

    Try this code:

    SharedPreferences sharedPreferences = getSharedPreferences("fake", Context.MODE_PRIVATE);
    SharedPreferences.Editor edit = sharedPreferences.edit();
    edit.clear().commit();
    
    0 讨论(0)
  • 2020-11-22 15:12
    String prefTag = "someTag";
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(applicationContext);
    prefs.edit().remove(prefTag).commit();
    

    This will delete the saved shared preferences with the name "someTag".

    0 讨论(0)
  • 2020-11-22 15:15

    You can also just manually uninstall your app using your device. Then when you re-install your app, shared preferences have been reset.

    0 讨论(0)
  • 2020-11-22 15:16

    Clear them all:

    PreferenceManager.getDefaultSharedPreferences(context).edit().clear().apply()
    
    0 讨论(0)
提交回复
热议问题