Android "remembers" Shared Preferences After Complete App Uninstall
Solution 1:
On (re)install, your app may be restoring files from Google auto-backup (via Google Drive). To disable this feature, you can explicitly set it to false in the manifest:
<manifest... >
...
<applicationandroid:allowBackup="false"... >
...
</application></manifest>
If you'd like more granular control over what is backed up/restored and what is not, you can include or exclude specific files from the backups.
See auto backup documentation: https://developer.android.com/guide/topics/data/autobackup#EnablingAutoBackup
If you don't want to disable auto backups, but want to reinstall with a "clean slate" (for testing purposes), you can do one of the following:
- Clear app data after reinstall. This will wipe out files that were restored automatically on install
- Clear app data prior to uninstall, then force a new backup (so old one gets reset) by using this command:
adb shell bmgr backupnow <PACKAGE>
See how to test backups documentation: https://developer.android.com/guide/topics/data/testingbackup#TestingBackup
Solution 2:
To extend on this, for example mobile/src/debug/AndroidManifest.xml
<applicationtools:replace="android:allowBackup"android:allowBackup="false">
...
</application>
Alike this one can disable auto-backup for debug builds - but keep it enabled for release builds.
Simply because disabling auto-backup for release builds might not be the intended outcome.
Solution 3:
Based on @hungryghost's suggestion the I eventually implemented a solution
Problem:Shared preferences can be remembered by Android after app reinstall and blanket instructions in the manifest along the lines of android:allowBackup = "false"
are not a solution.
So why not turn the problem into a solution on its own? Here is what I do
- Check shared preferences for a build specific key.
If that key is not found I do two things
- Clear out all shared preferences,
context.deleteSharedPrefernces(filename)
- Now create that build specific key
- When I make app changes that require old preferences to be forgotten I simply change the build specific key.
- Clear out all shared preferences,
Post a Comment for "Android "remembers" Shared Preferences After Complete App Uninstall"