#7851·libgdx

Preferences: report whether a flush actually persisted

Author: MRZ07Created Aug 22, 2026Updated Sep 4, 2026
Labelsenhancement

libGDX Issue Draft

Title: Preferences: report whether a flush actually persisted

Body:

Preferences.flush() gives no way to tell if the write reached disk. Each backend fails differently and none of them report it:

  • Android: SharedPreferences.Editor.apply() — async, failures dropped silently
  • LWJGL3: throws GdxRuntimeException
  • iOS: writeToFile(...) returns a boolean that gets ignored
  • GWT/Headless: no signal at all

Anyone doing transactional saves (write → verify → rollback) has to rebuild this per backend. We hit it shipping gamepad profile persistence and ended up wrapping every backend ourselves just to recover a boolean.

Related: #7351 (same Android root cause, closed without a fix — this generalizes it to all backends).

Affected: all backends, current master (1.13.2-SNAPSHOT era).

Proposal: add an additive default boolean save() on Preferences:

java
/** Persists the preferences.
 *  @return true if persisted. Default delegates to {@link #flush()} and reports
 *          success; backends override with real results. */
default boolean save () {
    flush();
    return true;
}

Backend overrides:

  • Android: editor.commit() instead of apply() — synchronous, real result. Documented as blocking; flush() stays for fire-and-forget.
  • LWJGL3: same XML store, catch → return false instead of throwing.
  • iOS: return the existing writeToFile boolean.
  • Headless/GWT: true, or try/catch → false where writes can fail.

Why additive: changing flush() to return boolean breaks compilation of every third-party Preferences implementation. A default method keeps them all valid and lets backends opt in one by one. Master is on Java 8+, so defaults are fine.

Happy to send the PR (interface + ~6 backend overrides + test) once the API shape has a thumbs-up.