关于Android应用程序更新问题应用程序、问题、Android

2023-09-05 05:41:12 作者:梦远无从寄

几个问题:

什么意义升级的应用程序对存储的数据,即preferences和数据库?系统是否执行干净的新版本上安装(即删除旧版本,然后安装新的),还是其他什么东西?

如果用户想保留存储的数据 - 说什么在共享preference或SQLite数据库值?

我如何可以模拟这个应用程序更新安装的情况?如果我有一个版本的'X'安装在我的emualator和我做的版本X + 1我正在 INSTALL_FAILED_ALREADY_EXIST 错误亚行安装。我应该尝试托管新的APK在Web服务器上,将程序包管理器以此为更新?

解决方案 所有的数据仍然存在(文件,preferences,数据库)。数据库是特殊的,你可以指定一个数据库版本,如果它检测到的版本​​改变了它会叫你的onUpgrade().对于所有其他人你负责,如果需要它们升级到新的版本中, 正如我在1称,Android仍然存在的一切。它是由你来处理你存储数据的方式的任何变化。 使用 ADB安装-r /path/to/newApk.apk (注意 -r 标志,告诉亚行研究 einstall)。基本上,工作流程应该如下:

 亚行卸载my.package
亚行安装/path/to/old.apk
#与应用程序中播放,设置preferences,数据库等。
亚行安装-r /path/to/new.apk
#看你的应用程序崩溃火灾的IM pressive球
#修复的东西
#转到0
 

其他注意事项:是,应用程序执行的洁净的安装新版本之前删除您的应用程序中。正如我所说的,但是,你的应用程序的数据不会被删除。不过,你要小心了,因为这会导致拆除的几件事情:

任何涉及到你的应用程序被杀死(所以如果你的应用程序正在运行 - 任何活动,服务,任何东西,所有组件都将被杀死)。 在任何有关您的应用程序从系统中删除,比如通知通过推 NotificationManager ,通过 AlarmManager ,等我不知道发生在你身上可能有任何小部件是什么(从未使用过的部件)。 Android程序开发实践教程 SDK更新失败

A few questions :

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?

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

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?

解决方案

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. As I said in 1, Android persists everything. It's up to you to handle any changes in the way you store your data. 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).