When I am working on my app in eclipse, is there a way to see the changes I make to the shared preferences of the app while it is debugging in the emulator? Thanks in advance
Asked
Active
Viewed 1.6k times
2 Answers
19
Run project in emulator, then from Eclipse choose menu Windows-> open perspective ->DDMS.
From tab device, choose emulator name, then go to file explorer,expand data->data->yourpackagename, you should see share reference xml file (only work on the emulator or a rooted device). Finally, export this file to windows.
See http://developer.android.com/tools/debugging/ddms.html
Update:
Another way, you can listen shared preference change:
SharedPreferences.OnSharedPreferenceChangeListener prefListener =
new SharedPreferences.OnSharedPreferenceChangeListener() {
public void onSharedPreferenceChanged(SharedPreferences prefs,String key) {
if (key.equals("YourKey"))
{
//Get this
}
}
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
preferences.registerOnSharedPreferenceChangeListener(prefListener);
See SharedPreferences.onSharedPreferenceChangeListener not being called consistently
-
Yes, but that method will only work on the emulator or a device where adb runs as root; otherwise you will need to use the run-as tool or have the app itself export the data. – Chris Stratton Jul 06 '12 at 03:59
-
I know, I recommend this way because taormania want to see in his emulator. – ductran Jul 06 '12 at 04:12
-
2To easily export the file from the DDMS perspective, just click on the "pull" button--it looks like a floppy disk with a red arrow pointing left into it. – SMBiggs Aug 30 '13 at 03:17
-
Is it possible to view an apps shared preferences that is live in production? (I hope not) – Micro Aug 18 '15 at 23:54
-
1@MicroR the answer is yes if device is rooted (because users have fully permission on rooted device, especially access the system files). If you want the security, you can try this https://github.com/scottyab/secure-preferences . This lib helps to encrypt the data save in SharedPreference – ductran Aug 19 '15 at 06:36
3
Running on emulator --> Go to file explorer --> data/data/yourapplication's package/Sharedpreferences.xml can be seen

Zoombie
- 3,590
- 5
- 33
- 40
-
2
-
1Not really, some application can allow its data to be extracted, if allowBackUp set to false in androidmanifest.xml file. – Zoombie Jan 07 '16 at 09:06
-
2with help of adb backup command, one can extract data of appllication. – Zoombie Jan 07 '16 at 09:07