在重新安装我的if语句中我的应用程序代码被尽管尚未已经建立了我的SharedPreferences进入访问。 我使用的是日食的模拟器,它需要的数据被清除比重新安装一些其他的方式? 谢谢
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();
}
}