Dec*_*nna 1 java android android-emulator sharedpreferences
重新安装我的应用程序后,尽管我的SharedPreferences条目尚未创建,但仍在访问我的if语句中的代码.我正在使用带有eclipse的模拟器,是否需要以重新安装的方式清除数据?谢谢
prefs = getSharedPreferences("appData", 0);
Gson gson = new Gson();
String gsonStr = prefs.getString("playerString", null);
if(gsonStr != null)
{
//This code is being accessed on the apps first onCreate() call prior to being reinstalled
Player[] tempArray = gson.fromJson(gsonStr, Player[].class);
Log.d("First Player", "" + tempArray[0]);
}
protected void onPause()
{
super.onPause();
if(savedPlayers != null)
{
Gson gson = new Gson();
String gsonStr = gson.toJson(savedPlayers.toArray());
prefs = getSharedPreferences("appData", 0);
SharedPreferences.Editor editor = prefs.edit();
//editor().clear();
Log.d("GSONString",gson.toString());
editor.putString("playerString", gsonStr);
editor.putInt("ArraySize", savedPlayers.size());
editor.commit();
}
}
Run Code Online (Sandbox Code Playgroud)
很可能该应用程序只是被重新安装.为了清除数据,实际上必须首先卸载应用程序.重新安装实际上不会清除数据.模拟器实际上允许运行时选项,它将在您运行模拟器时擦除所有用户数据,但我不相信它每次运行应用程序时都会运行.如果您正在使用eclipse,则可以在应用程序的"运行配置"中设置此选项.
要从模拟器内部进行操作,请转到settings-> applications-> manage applications-> your app-> clear data
| 归档时间: |
|
| 查看次数: |
407 次 |
| 最近记录: |