5

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.

3 Answers 3

8

For the following procedure you'll need 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 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).

6
  • After one hour Iv'e managed to do what you wrote. It took some time as all about Android SDK was new to me. I managed to re-install the game, and the personal data seemed to be there. But unluckily the game would still not load. Only after I removed the personal data.
    – Tim
    Commented Oct 26, 2013 at 20:38
  • Yeah, I was afraid of that. It still could have been the Dalvik cache being messed up, but then an update/re-install (without uninstall before) should have cured that (so the app's own data being messed up was the logical conclusion). But it was worth a try. And having ADB running from your computer gives you a bunch of other options (see the adb tag-wiki for hints on that).
    – Izzy
    Commented Oct 26, 2013 at 21:17
  • 1
    You must be root in order to uninstall an app. To become root, you must either launch adb shell from a computer or else you must root your phone and use the su command. If your phone is not rooted, a terminal emulator won't allow you to uninstall anything. Commented Jul 13, 2015 at 12:43
  • 1
    @Izzy: My mistake. I experimented further. adb shell indeed lacks root privileges. But it does get enough permissions to run pm uninstall -k. Still, my terminal emulator (jackpal.androidterm) does not have sufficient permissions to run pm uninstall -k: when I try it, pm gives me a "Permission denied" error. I did my testing in Android "Jelly Bean" 4.1.2. I wonder if, on a newer OS version, App Ops could grant more permissions to my terminal emulator? Commented Jul 16, 2015 at 13:00
  • 1
    I doubt that, @unforgettableid – it's adbd which gets "elevated privileges" (which it e.g. requires for adb backup). Terminal is dealt with like a "normal app" – so unless it explicitly requests additional permissions, it won't get them.
    – Izzy
    Commented Jul 16, 2015 at 13:12
1

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.

1
  • Android has this function, even built-in ;) See my answer. Works without root.
    – Izzy
    Commented Oct 26, 2013 at 18:22
1

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
1
  • I will just add that now you must use cmd package list packages -f -3 and that in that cut -d= -f1 did not work for every package, as some paths include base64 padding (= characters), but was able to use regex in a text editor to process the list, and then use cat with the last part of your one-liner. Commented Dec 3, 2018 at 5:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .