View an Android App's shared preferences?

taormania picture taormania · Jul 6, 2012 · Viewed 15.4k times · Source

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

Answer

R4j picture R4j · Jul 6, 2012

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