Android: Use apply() instead of commit() for SharedPreference changes.
apply() changes the in-memory instance of SharedPreferences and writes to the disk asynchronously, rather than synchronously, which commit() does. Since these are done on the UI thread, they should be asynchronous.
This commit is contained in:
parent
6eb2b6ef7a
commit
053f5c1f17
|
@ -190,13 +190,13 @@ public final class EmulationActivity extends Activity
|
||||||
{
|
{
|
||||||
overlay.setVisibility(View.VISIBLE);
|
overlay.setVisibility(View.VISIBLE);
|
||||||
item.setTitle(R.string.disable_input_overlay);
|
item.setTitle(R.string.disable_input_overlay);
|
||||||
sharedPrefs.edit().putBoolean("showInputOverlay", true).commit();
|
sharedPrefs.edit().putBoolean("showInputOverlay", true).apply();
|
||||||
}
|
}
|
||||||
else // Hide the overlay
|
else // Hide the overlay
|
||||||
{
|
{
|
||||||
overlay.setVisibility(View.INVISIBLE);
|
overlay.setVisibility(View.INVISIBLE);
|
||||||
item.setTitle(R.string.enable_input_overlay);
|
item.setTitle(R.string.enable_input_overlay);
|
||||||
sharedPrefs.edit().putBoolean("showInputOverlay", false).commit();
|
sharedPrefs.edit().putBoolean("showInputOverlay", false).apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -96,7 +96,7 @@ public final class UserPreferences
|
||||||
editor.putBoolean("fastDepthCalculation", getConfig("gfx_opengl.ini", "Settings", "FastDepthCalc", "True").equals("True"));
|
editor.putBoolean("fastDepthCalculation", getConfig("gfx_opengl.ini", "Settings", "FastDepthCalc", "True").equals("True"));
|
||||||
|
|
||||||
// Apply the changes.
|
// Apply the changes.
|
||||||
editor.commit();
|
editor.apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Small utility method that shortens calls to NativeLibrary.GetConfig.
|
// Small utility method that shortens calls to NativeLibrary.GetConfig.
|
||||||
|
|
|
@ -156,7 +156,7 @@ public final class OverlayConfigButton extends Button implements OnTouchListener
|
||||||
SharedPreferences.Editor editor = sharedPrefs.edit();
|
SharedPreferences.Editor editor = sharedPrefs.edit();
|
||||||
editor.putFloat(buttonId+"-X", getX());
|
editor.putFloat(buttonId+"-X", getX());
|
||||||
editor.putFloat(buttonId+"-Y", getY());
|
editor.putFloat(buttonId+"-Y", getY());
|
||||||
editor.commit();
|
editor.apply();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -159,7 +159,7 @@ public final class VideoSettingsFragment extends PreferenceFragment
|
||||||
// Get an editor.
|
// Get an editor.
|
||||||
SharedPreferences.Editor editor = sPrefs.edit();
|
SharedPreferences.Editor editor = sPrefs.edit();
|
||||||
editor.putString("gpuPref", "Software Renderer");
|
editor.putString("gpuPref", "Software Renderer");
|
||||||
editor.commit();
|
editor.apply();
|
||||||
videoBackends.setValue("Software Renderer");
|
videoBackends.setValue("Software Renderer");
|
||||||
videoBackends.setSummary("Software Renderer");
|
videoBackends.setSummary("Software Renderer");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue