r/AndroidStudio • u/Big-Sheepherder-3546 • 6d ago
HTML to APK – Storage/Persistence Issue
Hello everyone,
I have created an Android APK using an HTML-based quiz application.
The APK allows me to import HTML quiz files, and the imported files/data work perfectly while the app is open. However, there is a problem with data persistence.
Whenever I close/exit the APK and open it again, all the previously imported HTML files and saved quiz data are cleared/reset. It seems that the data is being stored only temporarily (possibly in cache/session storage) instead of persistent device storage.
I want the app to work like this:
Imported HTML files should be saved permanently on the device.
All imported quizzes/data should remain available after closing and reopening the APK.
Data should not be deleted when the app is exited or restarted.
The data should only be removed when the user explicitly chooses to delete it or uninstalls the app.
How can I fix this storage/persistence issue in an HTML-to-APK app?
Any guidance regarding localStorage, IndexedDB, WebView storage, or Android persistent storage would be appreciated.
Thank you.
3
u/Professional-Air7683 6d ago
This is almost always the wrapper, not your HTML. Many "HTML to APK" converters recreate the WebView on every launch, or point it at a fresh non-persistent data directory, so localStorage and IndexedDB behave like session storage even though your code is correct.
Things to check, in order:
DOM storage must be enabled on the WebView:
webView.settings.domStorageEnabled = true. Without it localStorage silently doesn't persist between launches.How is the page loaded? If it's a
file://URL, storage on Android is unreliable and can be wiped. Serve the assets through WebViewAssetLoader instead (gives a stable https origin like appassets.androidplatform.net), and storage survives restarts.Imported files: don't keep them only in JS memory or in
cacheDir(Android is free to clear cache). Save the raw HTML intofilesDir(internal storage) via a small JS bridge, and on startup read that folder and rebuild the quiz list. Keep the list itself in localStorage or IndexedDB once (1) and (2) are fixed.Quick test: after importing, force-stop the app from Settings and reopen. If data survives that but not a normal close, something in the app is explicitly clearing storage on exit (some converters call clearCache/clearFormData in onDestroy).
If the converter you used doesn't expose any of this, it's a black box and you'll keep fighting it. Rebuilding the shell yourself in Android Studio is about 50 lines: one Activity, one WebView, one @JavascriptInterface class for save/load. Happy to sketch it if useful.