-2
我有一個sharedpreferences,它保存和檢索數據正確。但問題是這個時候手機重新啓動它給空值。android sharedpreferences當應用程序或手機重新啓動時得到空
這裏是代碼,我有嘗試
if(encodedImage_profile3!=null)
{
wallpaper_sharedprefrences_profile3 = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences.Editor edit = wallpaper_sharedprefrences_profile3.edit();
edit.putString(PROFILE2_WALLPAPER, encodedImage_profile3);
edit.commit();
// Toast.makeText(context, "new same image in prefrences", Toast.LENGTH_SHORT).show();
}
wallpaper_sharedprefrences_profile3 = PreferenceManager.getDefaultSharedPreferences(context);
final String load_wallpaper_profile3 =wallpaper_sharedprefrences_profile3.getString(PROFILE2_WALLPAPER, "");
我也試試這個
if(encodedImage_profile3!=null)
{
wallpaper_sharedprefrences_profile3 = context.getSharedPreferences(PREF_PROFILE2_WALLPAPER, Context.MODE_PRIVATE);
SharedPreferences.Editor edit = wallpaper_sharedprefrences_profile3.edit();
edit.putString(PROFILE2_WALLPAPER, encodedImage_profile3);
edit.commit();
}
wallpaper_sharedprefrences_profile3 = context.getSharedPreferences(PREF_PROFILE2_WALLPAPER, Context.MODE_PRIVATE);
final String load_wallpaper_profile3 =wallpaper_sharedprefrences_profile3.getString(PROFILE2_WALLPAPER, "");
你需要設置申請一次完成編輯共享偏好..... – silverFoxA
當你明確地將默認值設置爲'「」'時,它是如何給出'null'值的?請發佈您的logcat輸出。 – earthw0rmjim
@silverFoxA他稱'commit()'。 – earthw0rmjim