开发者

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 t开发者_运维知识库he same thing?

SharedPreferences settings = getSharedPreferences(PREF_FILE_NAME, 0);
Editor e = settings.edit();
e.clear(); 
e.commit();


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.)


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


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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜