Android “remembers” shared preferences after complete app uninstall
In my Android app I use a set of randomly generated file names to store some data. In order to ensure that the same set of file names are generated at app restart - and are yet different for each app installation - I start off the process by picking the names as substrings from a long string of random alphanumeric characters which I generate when the app is installed. This latter string is stored in Shared Prefereneces.
As I am testing out the app I have run into a rather peculiar issue. From time-to-time I make major changes so I fully uninstall the app - and even Force Close it + clear all its data. At that point I would expect that the device would have no "prior knowledge" of the app if it is reinstalled. And yet I find that the Shared Preferences string is somehow "remembered". This causes havoc if in the interim I have changed how the file name substrings are picked up from the stored shared preferences string.
How can I ensure that the app has "zero memory" of a previously installed version that has subsequently been uninstalled?
One solution I have used in the past is to instruct Android not to do any backups via the manifest file, android:allowBackup = "false"
. However, I have backed away from that idea since - unless I am mistaken - it effectively means that I am stopping the user from porting their app over to a new device when they decide to change handsets.
android sharedpreferences
add a comment |
In my Android app I use a set of randomly generated file names to store some data. In order to ensure that the same set of file names are generated at app restart - and are yet different for each app installation - I start off the process by picking the names as substrings from a long string of random alphanumeric characters which I generate when the app is installed. This latter string is stored in Shared Prefereneces.
As I am testing out the app I have run into a rather peculiar issue. From time-to-time I make major changes so I fully uninstall the app - and even Force Close it + clear all its data. At that point I would expect that the device would have no "prior knowledge" of the app if it is reinstalled. And yet I find that the Shared Preferences string is somehow "remembered". This causes havoc if in the interim I have changed how the file name substrings are picked up from the stored shared preferences string.
How can I ensure that the app has "zero memory" of a previously installed version that has subsequently been uninstalled?
One solution I have used in the past is to instruct Android not to do any backups via the manifest file, android:allowBackup = "false"
. However, I have backed away from that idea since - unless I am mistaken - it effectively means that I am stopping the user from porting their app over to a new device when they decide to change handsets.
android sharedpreferences
2
We had same issue and get resolved byandroid:allowBackup="false"
inAndroidManifest.xml.
now try it with new device, it should have resolved. I have no idea how it worked.
– Rumit Patel
Nov 17 '18 at 5:37
Thanks for the comment. I have changed my question a bit. I had tried theandroid:allowBackup
approach but find that it can raise other issues as I explain now.
– DroidOS
Nov 17 '18 at 5:46
I just saw these comments and your updated question. I'll revise my answer.
– hungryghost
Nov 17 '18 at 5:50
add a comment |
In my Android app I use a set of randomly generated file names to store some data. In order to ensure that the same set of file names are generated at app restart - and are yet different for each app installation - I start off the process by picking the names as substrings from a long string of random alphanumeric characters which I generate when the app is installed. This latter string is stored in Shared Prefereneces.
As I am testing out the app I have run into a rather peculiar issue. From time-to-time I make major changes so I fully uninstall the app - and even Force Close it + clear all its data. At that point I would expect that the device would have no "prior knowledge" of the app if it is reinstalled. And yet I find that the Shared Preferences string is somehow "remembered". This causes havoc if in the interim I have changed how the file name substrings are picked up from the stored shared preferences string.
How can I ensure that the app has "zero memory" of a previously installed version that has subsequently been uninstalled?
One solution I have used in the past is to instruct Android not to do any backups via the manifest file, android:allowBackup = "false"
. However, I have backed away from that idea since - unless I am mistaken - it effectively means that I am stopping the user from porting their app over to a new device when they decide to change handsets.
android sharedpreferences
In my Android app I use a set of randomly generated file names to store some data. In order to ensure that the same set of file names are generated at app restart - and are yet different for each app installation - I start off the process by picking the names as substrings from a long string of random alphanumeric characters which I generate when the app is installed. This latter string is stored in Shared Prefereneces.
As I am testing out the app I have run into a rather peculiar issue. From time-to-time I make major changes so I fully uninstall the app - and even Force Close it + clear all its data. At that point I would expect that the device would have no "prior knowledge" of the app if it is reinstalled. And yet I find that the Shared Preferences string is somehow "remembered". This causes havoc if in the interim I have changed how the file name substrings are picked up from the stored shared preferences string.
How can I ensure that the app has "zero memory" of a previously installed version that has subsequently been uninstalled?
One solution I have used in the past is to instruct Android not to do any backups via the manifest file, android:allowBackup = "false"
. However, I have backed away from that idea since - unless I am mistaken - it effectively means that I am stopping the user from porting their app over to a new device when they decide to change handsets.
android sharedpreferences
android sharedpreferences
edited Nov 17 '18 at 5:45
DroidOS
asked Nov 17 '18 at 5:31
DroidOSDroidOS
3,10674798
3,10674798
2
We had same issue and get resolved byandroid:allowBackup="false"
inAndroidManifest.xml.
now try it with new device, it should have resolved. I have no idea how it worked.
– Rumit Patel
Nov 17 '18 at 5:37
Thanks for the comment. I have changed my question a bit. I had tried theandroid:allowBackup
approach but find that it can raise other issues as I explain now.
– DroidOS
Nov 17 '18 at 5:46
I just saw these comments and your updated question. I'll revise my answer.
– hungryghost
Nov 17 '18 at 5:50
add a comment |
2
We had same issue and get resolved byandroid:allowBackup="false"
inAndroidManifest.xml.
now try it with new device, it should have resolved. I have no idea how it worked.
– Rumit Patel
Nov 17 '18 at 5:37
Thanks for the comment. I have changed my question a bit. I had tried theandroid:allowBackup
approach but find that it can raise other issues as I explain now.
– DroidOS
Nov 17 '18 at 5:46
I just saw these comments and your updated question. I'll revise my answer.
– hungryghost
Nov 17 '18 at 5:50
2
2
We had same issue and get resolved by
android:allowBackup="false"
in AndroidManifest.xml.
now try it with new device, it should have resolved. I have no idea how it worked.– Rumit Patel
Nov 17 '18 at 5:37
We had same issue and get resolved by
android:allowBackup="false"
in AndroidManifest.xml.
now try it with new device, it should have resolved. I have no idea how it worked.– Rumit Patel
Nov 17 '18 at 5:37
Thanks for the comment. I have changed my question a bit. I had tried the
android:allowBackup
approach but find that it can raise other issues as I explain now.– DroidOS
Nov 17 '18 at 5:46
Thanks for the comment. I have changed my question a bit. I had tried the
android:allowBackup
approach but find that it can raise other issues as I explain now.– DroidOS
Nov 17 '18 at 5:46
I just saw these comments and your updated question. I'll revise my answer.
– hungryghost
Nov 17 '18 at 5:50
I just saw these comments and your updated question. I'll revise my answer.
– hungryghost
Nov 17 '18 at 5:50
add a comment |
3 Answers
3
active
oldest
votes
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 ... >
...
<application android: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
I am accepting and upvoting your answer because you put me on the right track here. I have provided my solution to the issue - based on what you suggested - as a separate answer for the benefit of others who might run into a similar situation.
– DroidOS
Nov 17 '18 at 6:18
add a comment |
to extend on this, for example mobile/src/debug/AndroidManifest.xml
<application
tools: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.
add a comment |
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,
context.deleteSharedPreferences(filename)
could also be executed at the click of a button (here I have one fragment only accessible in debug builds, barely for test/debug related preferences).
– Martin Zeitler
Nov 17 '18 at 6:47
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53348539%2fandroid-remembers-shared-preferences-after-complete-app-uninstall%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
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 ... >
...
<application android: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
I am accepting and upvoting your answer because you put me on the right track here. I have provided my solution to the issue - based on what you suggested - as a separate answer for the benefit of others who might run into a similar situation.
– DroidOS
Nov 17 '18 at 6:18
add a comment |
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 ... >
...
<application android: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
I am accepting and upvoting your answer because you put me on the right track here. I have provided my solution to the issue - based on what you suggested - as a separate answer for the benefit of others who might run into a similar situation.
– DroidOS
Nov 17 '18 at 6:18
add a comment |
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 ... >
...
<application android: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
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 ... >
...
<application android: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
edited Nov 17 '18 at 6:24
answered Nov 17 '18 at 5:47
hungryghosthungryghost
5,67511634
5,67511634
I am accepting and upvoting your answer because you put me on the right track here. I have provided my solution to the issue - based on what you suggested - as a separate answer for the benefit of others who might run into a similar situation.
– DroidOS
Nov 17 '18 at 6:18
add a comment |
I am accepting and upvoting your answer because you put me on the right track here. I have provided my solution to the issue - based on what you suggested - as a separate answer for the benefit of others who might run into a similar situation.
– DroidOS
Nov 17 '18 at 6:18
I am accepting and upvoting your answer because you put me on the right track here. I have provided my solution to the issue - based on what you suggested - as a separate answer for the benefit of others who might run into a similar situation.
– DroidOS
Nov 17 '18 at 6:18
I am accepting and upvoting your answer because you put me on the right track here. I have provided my solution to the issue - based on what you suggested - as a separate answer for the benefit of others who might run into a similar situation.
– DroidOS
Nov 17 '18 at 6:18
add a comment |
to extend on this, for example mobile/src/debug/AndroidManifest.xml
<application
tools: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.
add a comment |
to extend on this, for example mobile/src/debug/AndroidManifest.xml
<application
tools: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.
add a comment |
to extend on this, for example mobile/src/debug/AndroidManifest.xml
<application
tools: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.
to extend on this, for example mobile/src/debug/AndroidManifest.xml
<application
tools: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.
edited Nov 21 '18 at 7:24
answered Nov 17 '18 at 5:51
Martin ZeitlerMartin Zeitler
16.1k34167
16.1k34167
add a comment |
add a comment |
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,
context.deleteSharedPreferences(filename)
could also be executed at the click of a button (here I have one fragment only accessible in debug builds, barely for test/debug related preferences).
– Martin Zeitler
Nov 17 '18 at 6:47
add a comment |
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,
context.deleteSharedPreferences(filename)
could also be executed at the click of a button (here I have one fragment only accessible in debug builds, barely for test/debug related preferences).
– Martin Zeitler
Nov 17 '18 at 6:47
add a comment |
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,
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,
answered Nov 17 '18 at 6:24
DroidOSDroidOS
3,10674798
3,10674798
context.deleteSharedPreferences(filename)
could also be executed at the click of a button (here I have one fragment only accessible in debug builds, barely for test/debug related preferences).
– Martin Zeitler
Nov 17 '18 at 6:47
add a comment |
context.deleteSharedPreferences(filename)
could also be executed at the click of a button (here I have one fragment only accessible in debug builds, barely for test/debug related preferences).
– Martin Zeitler
Nov 17 '18 at 6:47
context.deleteSharedPreferences(filename)
could also be executed at the click of a button (here I have one fragment only accessible in debug builds, barely for test/debug related preferences).– Martin Zeitler
Nov 17 '18 at 6:47
context.deleteSharedPreferences(filename)
could also be executed at the click of a button (here I have one fragment only accessible in debug builds, barely for test/debug related preferences).– Martin Zeitler
Nov 17 '18 at 6:47
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53348539%2fandroid-remembers-shared-preferences-after-complete-app-uninstall%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
We had same issue and get resolved by
android:allowBackup="false"
inAndroidManifest.xml.
now try it with new device, it should have resolved. I have no idea how it worked.– Rumit Patel
Nov 17 '18 at 5:37
Thanks for the comment. I have changed my question a bit. I had tried the
android:allowBackup
approach but find that it can raise other issues as I explain now.– DroidOS
Nov 17 '18 at 5:46
I just saw these comments and your updated question. I'll revise my answer.
– hungryghost
Nov 17 '18 at 5:50