Preferences API and Backup Restoration: Key Retention After Schema Changes
0 reputation · 17 Jan 2021, 01:24 UTC
0 reputation · 17 Jan 2021, 01:24 UTC
Libgdx Preferences persist key-value pairs across Android, iOS and desktop via platform-specific storage abstraction.
When a newer app version removes a previously stored key, restoration from an older backup may produce incomplete data on platforms that retain the original preference file structure.
The precise goal is to determine how the Preferences API's restoration mechanism handles schema evolution, specifically whether omitted keys are silently omitted, defaulted, or cause restoration failure across supported platforms.
Constraints include platform-specific file paths that are not directly portable between devices and the version-sensitive behavior where key removal in newer releases can result in missing data when older saves are loaded on newer app versions.
What guarantees does the restoration process provide for data completeness when key sets diverge between app versions, and does the backup format preserve sufficient metadata to reconstruct the original preference state?
Can platform-specific storage differences affect the reliability of cross-version preference restoration, and what workarounds exist for maintaining backward compatibility?
37275 reputation · 17 Jan 2021, 10:39 UTC
The Libgdx Preferences API provides no automatic schema migration when restoring backups after keys are removed in a newer app version. Restoration is incomplete by default: keys absent from the current code are silently omitted or replaced with defaults, and the backup format stores only raw key-value pairs without schema metadata, so the original preference state cannot be reconstructed automatically.
Confirmed: Android SharedPreferences, iOS UserDefaults, and desktop property-file backends each expose stored values through the running app’s Preferences instance. Keys not recognized by the current build are not surfaced to application code.
Likely explanation: when an older backup is restored onto a newer version, the platform loader repopulates storage, but the app reads only keys it knows. Removed keys are therefore invisible to the app even if bytes remain in the file.
| Platform | Backend | Removed-key behavior on restore | Completeness guarantee |
|---|---|---|---|
| Android | SharedPreferences XML | Silently omitted; default returned | Incomplete |
| iOS | UserDefaults plist | Ignored on read; backup retains pairs | Incomplete |
| Desktop | Properties/Preferences file | May persist until overwritten; flush can truncate | Unreliable |
pref_version key and store the current schema version.# Android: inspect current preference file
adb shell run-as com.your.app cat files/prefs.xml
# iOS simulator: locate plist under the app container
~/Library/Developer/CoreSimulator/Devices//data/Containers/Data/Application//Library/Preferences/
# Desktop: inspect properties file location used by your backend
# Windows: %APPDATA%\your-app\prefs.properties
# Linux/macOS: ~/.prefs/your-app/prefs.properties
Which Libgdx version are you targeting? Versions before 1.9.10 lack built-in backup/restore APIs, so behavior depends entirely on platform defaults. Recent versions may include a PreferencesBackup helper, but it still performs no schema migration.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.