Deleting shared preferences

0 votes
asked Sep 10, 2010 by andrew

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.

17 Answers

0 votes
answered Jan 21, 2010 by kdahlhaus

Just did this this morning. From a command prompt:

adb shell
cd /data/data/YOUR_PACKAGE_NAME/shared_prefs
rm * // to remove all shared preference files
rm YOUR_PREFS_NAME.xml // to remove a specific shared preference file

NOTE: This requires a rooted device such as the stock Android virtual devices, a Genymotion device, or an actual rooted handset/tablet, etc.

0 votes
answered Sep 10, 2010 by mark-b

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.

0 votes
answered Sep 7, 2011 by vaibhav-vijay

My solution:

SharedPreferences preferences = getSharedPreferences("Mypref", 0);
preferences.edit().remove("shared_pref_key").commit();
0 votes
answered Jan 2, 2012 by iewnait

The fastest way to do this while you are developing/testing would be to

adb uninstall

Example: $ adb uninstall com.example.myappname

0 votes
answered Jan 18, 2012 by nobu

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

0 votes
answered Jan 10, 2013 by johnson-wong

You can use the adb shell to do this even without a rooted phone. The only catch is that the app must be debuggable.

run-as <your package name> <command>

For example:

run-as com.asdf.blah rm /data/data/com.asdf.blah/databases/myDB.db

Alternatively, you can just do the above but without the command which will direct you to the app package root and allow you to execute more commands in the app's context.

0 votes
answered Jan 29, 2013 by zserghei

Removing all preferences:

SharedPreferences settings = context.getSharedPreferences("PreferencesName", Context.MODE_PRIVATE);
settings.edit().clear().commit();

Removing single preference:

SharedPreferences settings = context.getSharedPreferences("PreferencesName", Context.MODE_PRIVATE);
settings.edit().remove("KeyName").commit();
0 votes
answered Jan 7, 2014 by vaishali-sutariya
Editor editor = getSharedPreferences("clear_cache", Context.MODE_PRIVATE).edit();
editor.clear();
editor.commit();
0 votes
answered Jan 19, 2014 by wizurd

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

0 votes
answered Jan 1, 2015 by ashish-jaiswal

You can use-> preferences.edit().remove("key").commit(); to delete saved value from shared preferences.

Welcome to Q&A, where you can ask questions and receive answers from other members of the community.
Website Online Counter

...