fix lint warning: CommitPrefEdits: use apply() instead of commit()

"Consider using apply() instead; commit writes its data to persistent
storage immediately, whereas apply will handle it in the background"

commit() is only useful if the code actually checks the return value.
This commit is contained in:
Hans-Christoph Steiner 2016-03-30 20:45:40 +02:00
parent c67a60271d
commit c3b47ecd5a
5 changed files with 11 additions and 11 deletions

View File

@ -40,7 +40,7 @@ public final class Preferences implements SharedPreferences.OnSharedPreferenceCh
if (preferences.getString(PREF_LOCAL_REPO_NAME, null) == null) { if (preferences.getString(PREF_LOCAL_REPO_NAME, null) == null) {
preferences.edit() preferences.edit()
.putString(PREF_LOCAL_REPO_NAME, getDefaultLocalRepoName()) .putString(PREF_LOCAL_REPO_NAME, getDefaultLocalRepoName())
.commit(); .apply();
} }
} }
@ -113,7 +113,7 @@ public final class Preferences implements SharedPreferences.OnSharedPreferenceCh
} }
public void setPrivilegedInstallerEnabled(boolean enable) { public void setPrivilegedInstallerEnabled(boolean enable) {
preferences.edit().putBoolean(PREF_PRIVILEGED_INSTALLER, enable).commit(); preferences.edit().putBoolean(PREF_PRIVILEGED_INSTALLER, enable).apply();
} }
public boolean isFirstTime() { public boolean isFirstTime() {
@ -121,7 +121,7 @@ public final class Preferences implements SharedPreferences.OnSharedPreferenceCh
} }
public void setFirstTime(boolean firstTime) { public void setFirstTime(boolean firstTime) {
preferences.edit().putBoolean(PREF_FIRST_TIME, firstTime).commit(); preferences.edit().putBoolean(PREF_FIRST_TIME, firstTime).apply();
} }
public boolean isPostPrivilegedInstall() { public boolean isPostPrivilegedInstall() {
@ -129,7 +129,7 @@ public final class Preferences implements SharedPreferences.OnSharedPreferenceCh
} }
public void setPostPrivilegedInstall(boolean postInstall) { public void setPostPrivilegedInstall(boolean postInstall) {
preferences.edit().putBoolean(PREF_POST_PRIVILEGED_INSTALL, postInstall).commit(); preferences.edit().putBoolean(PREF_POST_PRIVILEGED_INSTALL, postInstall).apply();
} }
public boolean shouldCacheApks() { public boolean shouldCacheApks() {
@ -149,7 +149,7 @@ public final class Preferences implements SharedPreferences.OnSharedPreferenceCh
} }
public void setShowNfcDuringSwap(boolean show) { public void setShowNfcDuringSwap(boolean show) {
preferences.edit().putBoolean(PREF_SHOW_NFC_DURING_SWAP, show).commit(); preferences.edit().putBoolean(PREF_SHOW_NFC_DURING_SWAP, show).apply();
} }
public boolean expertMode() { public boolean expertMode() {

View File

@ -406,7 +406,7 @@ public class UpdateService extends IntentService implements ProgressListener {
SharedPreferences.Editor e = prefs.edit(); SharedPreferences.Editor e = prefs.edit();
e.putLong(Preferences.PREF_UPD_LAST, System.currentTimeMillis()); e.putLong(Preferences.PREF_UPD_LAST, System.currentTimeMillis());
e.commit(); e.apply();
if (errorRepos == 0) { if (errorRepos == 0) {
if (changes) { if (changes) {

View File

@ -141,7 +141,7 @@ public abstract class AppListFragment extends ListFragment implements
boolean hasTriedEmptyUpdate = prefs.getBoolean(triedEmptyUpdate, false); boolean hasTriedEmptyUpdate = prefs.getBoolean(triedEmptyUpdate, false);
if (!hasTriedEmptyUpdate) { if (!hasTriedEmptyUpdate) {
Utils.debugLog(TAG, "Empty app list, and we haven't done an update yet. Forcing repo update."); Utils.debugLog(TAG, "Empty app list, and we haven't done an update yet. Forcing repo update.");
prefs.edit().putBoolean(triedEmptyUpdate, true).commit(); prefs.edit().putBoolean(triedEmptyUpdate, true).apply();
UpdateService.updateNow(getActivity()); UpdateService.updateNow(getActivity());
return true; return true;
} }

View File

@ -230,7 +230,7 @@ public class AvailableAppsFragment extends AppListFragment implements
Context.MODE_PRIVATE); Context.MODE_PRIVATE);
SharedPreferences.Editor e = p.edit(); SharedPreferences.Editor e = p.edit();
e.putString(CATEGORY_KEY, currentCategory); e.putString(CATEGORY_KEY, currentCategory);
e.commit(); e.apply();
} }
@Override @Override

View File

@ -204,13 +204,13 @@ public class PreferencesFragment extends PreferenceFragment
// privileged permission are granted, i.e. the extension is installed correctly // privileged permission are granted, i.e. the extension is installed correctly
SharedPreferences.Editor editor = pref.getSharedPreferences().edit(); SharedPreferences.Editor editor = pref.getSharedPreferences().edit();
editor.putBoolean(Preferences.PREF_PRIVILEGED_INSTALLER, true); editor.putBoolean(Preferences.PREF_PRIVILEGED_INSTALLER, true);
editor.commit(); editor.apply();
pref.setChecked(true); pref.setChecked(true);
} else { } else {
// privileged permission not available // privileged permission not available
SharedPreferences.Editor editor = pref.getSharedPreferences().edit(); SharedPreferences.Editor editor = pref.getSharedPreferences().edit();
editor.putBoolean(Preferences.PREF_PRIVILEGED_INSTALLER, false); editor.putBoolean(Preferences.PREF_PRIVILEGED_INSTALLER, false);
editor.commit(); editor.apply();
pref.setChecked(false); pref.setChecked(false);
AlertDialog.Builder alertBuilder = new AlertDialog.Builder(getActivity()); AlertDialog.Builder alertBuilder = new AlertDialog.Builder(getActivity());
@ -248,7 +248,7 @@ public class PreferencesFragment extends PreferenceFragment
} else { } else {
SharedPreferences.Editor editor = pref.getSharedPreferences().edit(); SharedPreferences.Editor editor = pref.getSharedPreferences().edit();
editor.putBoolean(Preferences.PREF_PRIVILEGED_INSTALLER, false); editor.putBoolean(Preferences.PREF_PRIVILEGED_INSTALLER, false);
editor.commit(); editor.apply();
pref.setChecked(false); pref.setChecked(false);
} }