所以這裏的傢伙是個問題,我擡頭看着這個可以SharedPreferences.Editor.commit()在同一個活動/片段中多次使用
http://developer.android.com/reference/android/content/SharedPreferences.Editor.html#commit%28%29
,並提到,「請注意,當兩個編輯同時修改首選項時,最後一個調用commit的成功。「
說我的活動是這樣的:
SharedPreferences.Editor editor();
onCreate(....)
{
//start the instance of editor
......
if(condition1)
editor.put...
editor.commit()
}
onPause()
{
if(condition1)
{
editor.commit()
}
}
請問
這項工作?因爲在我的應用程序中,我必須在線時存儲用戶憑據,並且在離線時(即condition1)記錄用戶標識的服務器(即記錄用戶標識)的服務器很少。 onPause是我做的地方。所以任何人都可以證實這一點。謝謝。
** putBoolean()似乎正常工作。這是一個龐大的代碼片斷,所以我可能會在用戶憑據邏輯的某處出錯。所以,我只是想用editor.commit()的用法來確認。*
是的。每次你想保存一個值,你都必須提交它。 – Prachur