I am maintaining a sessions using Shared Preferences, when I update to latest version I am getting a login screen again. Why? And Is there any solution to maintain a Shared Preferences data even after update of application?
Asked
Active
Viewed 67 times
0
-
What types are you saving in shared preferences ? Object or simple types ? – Misha Akopov Dec 19 '17 at 09:05
-
Shared preferences are not supposed to be cleared on update. From android M onwards, you could set android:allowBackup="true in the application level of your manifest to retain it. Regarding the explanation to your question, you can read this You could check this https://stackoverflow.com/a/12637972/1840795 – Nakul Sudhakar Dec 19 '17 at 09:06
-
**No** Shared preference will not clear automatically on updating app from play store. There might be some other issue. check this answer : https://stackoverflow.com/questions/12637737/what-will-happen-to-the-sharedpreferences-on-update-an-android-app – rathodbhavikk Dec 19 '17 at 09:06
-
@MishaAkopov Its just a userId and boolean I am saving in shared preferences. – Govind Rastogi Dec 19 '17 at 09:18
-
@NakulSudhakar I have added android:allowBackup="true" in my manifest. – Govind Rastogi Dec 19 '17 at 09:19
1 Answers
0
For maintaining session in your app you can use sqlite for storing session. When you will use sqlite then it will not delete data you saved in it but for that you have to code well.
for the first time you can use onCreate() method of sqliteopenheloper class for creating table and
When you want to upgrade your app version then you have to use onUpgrade() methods of SqliteOpenhelper but you have to properly implement the onUpgrade() mehtod then only you will not loose your previous saved session.

Vishwa Pratap
- 374
- 6
- 14