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