How do you re-install an app without losing personal data?
In this case its Plants vs. Zombies 2 that hangs when loading the game. I thought a re-install might solve the issue. But I don't want to need to redo everything I've done so far.
Android Enthusiasts Stack Exchange is a question and answer site for enthusiasts and power users of the Android operating system. It only takes a minute to sign up.Sign up to join this community
For the following procedure you'll need adb installed on your computer (if you're not already have that, see: Is there a minimal installation of ADB?). Alternatively, a terminal emulator app should do as well.
Android apps are managed by the "Package manager", which has a command-line interface called
pm. So here's what you can do with it for your case:
# to use ADB, first get a command line adb shell # now tell the package manager to uninstall the app, but keep its data pm uninstall -k com.YOUR_PACKAGE_NAME`
(Note this won't work with a terminal emulator app on device (at least with none I know of) except with root permissions, as "normal apps" lack the required privileges/permissions.)
Of course you have to replace
com.YOUR_PACKAGE_NAME with the package name of the app you want to deal with. Easiest way to find that is visiting its page on Google Play, and take a look at the URL: the package name follows the
id= parameter there. It's the
-k parameter telling the package manager to keep the app's data.
Now, when you re-install the app, its data is already there (was not removed).
All this does not require root (at least as long as we talk about a user-installed app).
Android hasn't got function which you described. If you have root access on your phone, you can make a copy of folder
/data/data/com.xxx.xxx, reinstall app, and overwrite generated folder by your copy.
You can also just reinstall the APK file that already exists on the device. After an upgrade to Android 6 somehow default permissions like
android.permission.ACCESS_NETWORK_STATE were lost, that is where this trick comes handy to discover the APK and reinstall it:
adb shell shell@hammerhead:/ $ pm path com.stackexchange.marvin /data/app/com.stackexchange.marvin-2/base.apk shell@hammerhead:/ $ pm install -r /data/app/com.stackexchange.marvin-2/base.apk pkg: /data/app/com.stackexchange.marvin-2/base.apk Success
Alternatively if you would like to reinstall a bunch of packages (
-3 for third-party packages only), you can parse the obtain the list of installed packages on the device and reinstall all of them with:
pm list packages -f -3 | cut -d: -f2 | cut -d= -f1 | while read apk; do pm install -r $apk; done