android: Use apply instead of commit for shared preferences
Previously we were operating on the assumption that apply'd settings wouldn't be visible immediately. This isn't true and settings will be accessible via memory before being stored to disk. This reduces any potential stutters caused by saving to shared preferences.
This commit is contained in:
parent
fcbf08ca98
commit
aeaddf407b
|
@ -249,7 +249,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
|
||||||
) { _, indexSelected, isChecked ->
|
) { _, indexSelected, isChecked ->
|
||||||
preferences.edit()
|
preferences.edit()
|
||||||
.putBoolean("buttonToggle$indexSelected", isChecked)
|
.putBoolean("buttonToggle$indexSelected", isChecked)
|
||||||
.commit()
|
.apply()
|
||||||
}
|
}
|
||||||
.setPositiveButton(android.R.string.ok) { _, _ ->
|
.setPositiveButton(android.R.string.ok) { _, _ ->
|
||||||
refreshInputOverlay()
|
refreshInputOverlay()
|
||||||
|
|
|
@ -758,8 +758,7 @@ class InputOverlay(context: Context, attrs: AttributeSet?) : SurfaceView(context
|
||||||
ButtonType.STICK_L.toString() + "-Y",
|
ButtonType.STICK_L.toString() + "-Y",
|
||||||
resources.getInteger(R.integer.SWITCH_STICK_L_Y).toFloat() / 1000 * maxY + minY
|
resources.getInteger(R.integer.SWITCH_STICK_L_Y).toFloat() / 1000 * maxY + minY
|
||||||
)
|
)
|
||||||
.commit()
|
.apply()
|
||||||
// We want to commit right away, otherwise the overlay could load before this is saved.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun isInEditMode(): Boolean {
|
override fun isInEditMode(): Boolean {
|
||||||
|
|
|
@ -57,6 +57,6 @@ object EmulationMenuSettings {
|
||||||
set(value) {
|
set(value) {
|
||||||
preferences.edit()
|
preferences.edit()
|
||||||
.putBoolean(Settings.PREF_MENU_SETTINGS_SHOW_OVERLAY, value)
|
.putBoolean(Settings.PREF_MENU_SETTINGS_SHOW_OVERLAY, value)
|
||||||
.commit()
|
.apply()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue