Questions about Android application update

2020-06-08 03:17发布

A few questions :

  1. What implications does upgrading an app have on stored data i.e. Preferences and database? Does the system perform a clean install of the new version(i.e. remove the older version and then install the new) or something else?

  2. What if the user wants to retain the stored data- say values in the shared preference or a sqlite database?

  3. How can I emulate this app-update-install scenario? If I have a version 'x' installed on my emualator and I do a adb install of version 'x+1' I am getting INSTALL_FAILED_ALREADY_EXIST error. Should I try hosting the new apk on a Web server, will the Package Manager take this as an update?

2条回答
虎瘦雄心在
2楼-- · 2020-06-08 03:51
  1. All data persists (files, preferences, databases). Databases are special as you can specify a database version and if it detects the version changed it will call your onUpgrade(). For all others you're responsible of updating them to the new version, if needed.
  2. As I said in 1, Android persists everything. It's up to you to handle any changes in the way you store your data.
  3. Use adb install -r /path/to/newApk.apk (notice the -r flag, which tells adb to reinstall). Basically, the workflow should be the following:

.

adb uninstall my.package
adb install /path/to/old.apk
# play with app, set preferences, databases, etc.
adb install -r /path/to/new.apk
# watch your app crash in an impressive ball of fire
# fix stuff
# goto 0

Other notes: Yes, the app performs a clean removal of your app before installing the new version. As I said, however, your app's data is not removed. Still, you have to be careful, because this removal causes a few things:

  • Any processes related to your app are killed (so if your app is running -- any activities, services, anything, all components will be killed).
  • Anything related to your app is removed from the system, like notifications pushed via the NotificationManager, alarms set via the AlarmManager, etc. I'm not sure what happens to any widgets you might have (never worked with widgets).
查看更多
Evening l夕情丶
3楼-- · 2020-06-08 03:54
  1. You have to take care about that for yourself. Look for onUpgrade() method i.e.
  2. As you have to take care for yourself, you can give the user the possibility to do everything.
  3. You should ensure you have the reinstall option set. Adb should update your application correctly than.
查看更多
登录 后发表回答