Prakash Kumar Prakash Kumar - 2 months ago 9
Android Question

When Android app gets updated how to get back data about the user from the shared preferences?

I have an

Android
app and I want to know, when a user updates my app from Play Store, what
Android
does in background? Does it uninstall the current version of my app and then install a new version?

I am facing a problem here that, suppose a user is logged in in my app and then he updates the app. Now all of my details about the user which was saved in my
SharedPreferences
will get lost and when the new version will get installed then this user have to log in again because as there will be no data in my
SharedPreferences
. I don't want my user to log in again, I want to save the state somewhere so that when the app gets updated user does not have to log in again.

Can anyone one of you tell me how all
Android
apps implement this functionality?

Answer

... when a user updates my app from Play Store, what Android does in background? Does it uninstall the current version of my app and then install a new version?

No. Once a new version of apk file has been downloaded from Play Store on a device, Android (or more precisely PackageManager) reinstalls it keeping app's data untouched by using, AFAIK, at least -r option.

That said, your SharedPreferences with the user login data will be kept after update.