View an Android App's shared preferences?

你。 提交于 2019-12-09 04:37:45

问题


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


回答1:


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




回答2:


Running on emulator --> Go to file explorer --> data/data/yourapplication's package/Sharedpreferences.xml can be seen



来源:https://stackoverflow.com/questions/11354904/view-an-android-apps-shared-preferences

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!