Deleting shared preferences


Question

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 wipe out some SharedPreferences values when I restart the app.

1
445
9/10/2010 6:34:52 PM

Accepted Answer

To remove specific values: SharedPreferences.Editor.remove() followed by a commit()

To remove them all SharedPreferences.Editor.clear() followed by a commit()

If you don't care about the return value and you're using this from your application's main thread, consider using apply() instead.

818
10/28/2016 11:01:44 PM

My solution:

SharedPreferences preferences = getSharedPreferences("Mypref", 0);
preferences.edit().remove("text").commit();

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon