Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I clear SharedPreferences from outside an Android application

Right now I can run the lines below to clear the preferences from within my application. But is there a way to do this outside my code? A command I can run from Eclipse or the emulator that can accomplish the same thing?

SharedPreferences settings = getSharedPreferences(PREF_FILE_NAME, 0);
Editor e = settings.edit();
e.clear(); 
e.commit();
like image 798
Newy Avatar asked Jan 12 '11 18:01

Newy


3 Answers

As an alternative to using the shell, you can also delete the files from Eclipse by going into the DDMS perspective, then choosing the File Browser tab (on the top right panel by default) and navigating to /data/data/<packagename>/shared_prefs and delete whichever preference files you want to by selecting them and pressing the red minus button at the top of the panel. (The red minus button doesn't work for entire folders. As far as I know, you have to use shell's rmdir command to get rid of those.)

like image 64
ArtOfWarfare Avatar answered Nov 19 '22 10:11

ArtOfWarfare


You can delete files from the settings on the device itself. Go to Settings --> Apps --> Your App --> Clear data.

(With 4.4 Kit Kat on a Nexus 7.)

Update:

For newer Android devices (8+) a faster way is: Long touch app icon --> Click App Info --> Click Storage --> Clear Data

like image 23
CorayThan Avatar answered Nov 19 '22 12:11

CorayThan


Use the adb shell to remove the preferences xml file from your app. There are a bunch of other tricks you can do via the shell as well. You can also nuke the preferences file via the file explorer via the eclipse plugin. You should be able to find preferences under /data/data/<packagename>/preferences or something like that (I don't have the path handy at the moment).

like image 40
Andrew White Avatar answered Nov 19 '22 12:11

Andrew White