android app install overwrites /data/data/com.my.app Background: As part of an upgrade to A6/MM, I ended up having to wipe my phone. I did however back up /data/app and /data/data before I wiped. After the upgrade I rsync'ed /data/data back to the phone. Then I proceeded to re-install some apps from google play.

I expected the app data in /data/data to be used, but instead the app install first failed, but on 2nd attempt the install worked (finished), BUT it overwrote all my settings (etc) that I had restored into /data/data. My question is, how do I avoid this? Was the first install fail because the app installer saw the old data?

The app in question was Zoiper Lite, but I don't think the specific app is terribly significant. Is there something about wiping (factory reset) that causes the apk install process to expect no data and therefore fail, but then erasing data if you insist with a 2nd attempt? Of course, what I really want is a workaround so I can install the app AND keep the old data. I have lots of apps for which I would like to do this, so it is definitely a problem...
DO NOT create the folders before the app itself does, as you often won't be able to get permissions, ownership and contexts right. Instead, after a new install, run the app once to let it create the file structure, then proceed to overwrite. It's also highly recommended to find which exact file(s) stores the preferences/data you want to restore - usually just some XML files in shared_prefs sub-folder - and restore them only.

The final solution to such problems in the future would be just using apps like Titanium Backup to automate the backup/restore process.

EDIT: I downloaded Zoiper myself and tested: I modified some preferences, backed up /data/data/com.zoiper.android.app/shared_prefs/com.zoiper.android.app_preferences.xml, then cleared data and re-ran the app to let it generate structure. I restored the pref file afterwards, and they did get restored after I did the 1st trick. The thing is, don't forget to first force close the app before you try to replace stuff, or the running app will simply ignore it.