我的問題很簡單,但我沒有找到答案(對不起,如果它在某個地方,只是沒有找到它)。sharedPreferences apply()保存所有以上或只是最後一個?怎麼運行的?
sharedpreferences.editor.apply()
如何工作?
要清楚,我有例如下面的代碼:
MainActivity.editor.putBoolean(somestring, someboolean);
MainActivity.editor.apply();
MainActivity.editor.putInt(somestring, someint);
MainActivity.editor.apply();
MainActivity.editor.putString(somestring,somestring);
MainActivity.editor.apply();
MainActivity.editor.putLong(somestring, somelong);
MainActivity.editor.apply();
MainActivity.editor.putLong(somestring, somelong);
MainActivity.editor.apply();
MainActivity.editor.putBoolean(somestring, someboolean);
MainActivity.editor.apply();
這工作在我的項目。但是,使用這個或以下的這個或這個性能更好嗎?
MainActivity.editor.putBoolean(somestring, someboolean);
MainActivity.editor.putInt(somestring, someint);
MainActivity.editor.putString(somestring,somestring);
MainActivity.editor.putLong(somestring, somelong);
MainActivity.editor.putLong(somestring, somelong);
MainActivity.editor.putBoolean(somestring, someboolean);
MainActivity.editor.apply();
基本上,上面的代碼是正確的?
以上所有putSomething
或apply()
只適用於一個putSomething
嗎?
非常感謝您的回答!你真的有幫助和指導! – PavTze