When I update application through popup implemented in application code on change of version shared preference persist but when update using auto-update or from updates available in play store shared preferences got removed?
Asked
Active
Viewed 848 times
0
-
What's your question? – Marcus Feb 16 '15 at 11:55
-
Simply adding a `?` at the end of a sentence doesn't make it a question - you have to be more specific. Provide code examples, describe your problem and what you've currently done. – Marcus Feb 16 '15 at 12:02
-
I am trying to show popup in my application when there is version update and give 2 option either to update and skip so when user click on update play store will open and user can update the application and after update on reopen user got auto login into application due to data(username) persist in shared preference but this doesn't happens when auto-login option is on and when update through updates available in play -store. – Karan Garg Feb 16 '15 at 12:12
-
I see. The problem is that SharedPreferences doesn't persist when a user uninstalls (or in your case update then re-install) an application. If you want to persist data outside of the application that persists even after uninstall, you will have to use an external server or service. – Marcus Feb 16 '15 at 12:14
-
I am wondering about that, usually, by only updating the app through playstore with deinstalling it before, the shared prefeences should persist. – Opiatefuchs Feb 16 '15 at 12:20
-
@marcus... i am only updating the app not reinstalling even in that case not able to find shared preference....but when update through code flow by forcefully deviating user to play store shared preference persist. – Karan Garg Feb 16 '15 at 12:33
1 Answers
0
You should have a look at SharedPreferencesBackupHelper.
Simply put, it backs up your SharedPreference
data when ever your app is uninstalled, or when ever you would like to back up your SharedPreferences
.
Additionally, this question also addresses your specific problem.
To manually request a restore, you call the requestRestore()
method. See this for reference.
Restore the calling application from backup. The data will be restored from the current backup dataset if the application has stored data there, or from the dataset used during the last full device setup operation if the current backup dataset has no matching data. If no backup data exists for this application in either source, a nonzero value will be returned.
-
-
As i found we only need to save the data and no need to restore so how i will manually call restore when i update app? – Karan Garg Feb 16 '15 at 13:50
-
@KaranGarg With the `requestRestore()` method, see the link I included in my answer. – Marcus Feb 16 '15 at 13:55
-
To use this is it necessary that backup and reset option should be enabled by user? – Karan Garg Feb 17 '15 at 07:47
-
-
@KaranGarg I could not find that it was necessary, but _if_ one would wish such a behavior, that could easily be implemented as a preference. – Marcus Feb 17 '15 at 11:00