1

我想发送我的 apk 更新,但我做了一些数据库更改,这会使应用程序崩溃。

所以用户必须卸载然后重新安装它。有没有办法部署一个apk,所以这是自动完成的。

或者清除之前安装的app数据。

4

4 回答 4

2

您可以提供onUpgrade()方法,然后您可以执行alter tableSQL 参见: http: //developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html,这需要您更改数据库版本号,以便在何时检测到应用程序启动。如果您的架构确实不同并且您想要保存现有数据,那么您应该将数据复制到临时表中,删除并创建架构并再次将其复制回来。

于 2012-04-08T19:04:19.847 回答
0

没有人会忽略/不阅读您在“新增功能”部分中提供的任何说明,并且您无法自动执行此操作。

您应该在应用程序中优雅地升级您的数据库。OpenHelper 类提供了执行此操作所需的所有功能。

http://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html

于 2012-04-08T19:01:45.190 回答
0

正如其他答案所表明的那样,您应该覆盖 onUpate() 方法以获得完美的用户体验。重新安装和清理很好......对我来说就像 1980 年的风格和 Android 的设计方式我几乎不怀疑它是受支持的。

因此,要回答最初的问题,不,我认为不可能通过其他应用程序管理应用程序。尽管我对执行此任务的任何方法缺乏了解并不能证明我认为这更多的是底层结构的问题。

Android 是一个基于 unix 的系统,每个应用程序都在该系统中注册为用户。在这种环境下,用户权限设置得很好,这意味着另一个用户(应用程序)不能轻易访问其他应用程序的数据,因此无法注入/劫持/优化代码。一个例外是例如 SD 卡等外部存储。在这里,每个具有正确权限的应用程序都可以随心所欲地四处游荡。

However back on the actual system there are some ways to grant applications to access foreign packages. However from what I've read it seems more to be designed for sharing specific information and settings. I doubt an uninstall routine will be found there.

Just before finishing I thought about the idea that your new application could ask the older version to remove itself and not start up unless is has done. For this approach maybe you find more information here. Is it possible to programmatically uninstall a package in Android

Nevertheless I also recommend you the onUpdate() solution since it's the way the system was designed and therefore the experience for the user will be much more satisfying and less complex.

于 2012-04-08T19:26:43.967 回答
0

I had a similar problem. In my case my app loaded a database from assets, and when upgrading the database didn't change. What I did to solve that was to change the database file name (in the assets folder) and worked perfectly, just like if I did another db. It's not the best way to fix it but it solves the problem.

于 2012-04-23T16:05:50.413 回答