[英]Why are my SharedPreferences entries not being cleared upon reinstalling?
重新安裝我的應用程序后,盡管尚未創建我的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();
}
}
很可能只是重新安裝了該應用程序。 為了清除數據,實際上必須先卸載該應用程序。 重新安裝實際上不會清除數據。 模擬器實際上允許使用運行時選項,該選項將在您運行模擬器時擦除所有用戶數據,但是我不相信它會在每次運行應用程序時運行。 如果使用eclipse,則可以在應用程序的“運行配置”中設置此選項。
要從模擬器內部執行此操作,請轉到設置->應用程序->管理應用程序->您的應用程序->清除數據
重新安裝后不會刪除共享的首選項和sqlite db。 要刪除它們,請轉到設置->應用程序->管理應用程序->單擊您的應用程序->單擊模擬器上的“清除數據” 。 這將清除存儲的數據。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.