I tested that it is possible for Android to pass newVersion < oldVersion to SQLiteOpenHelper.onUpgrade() method, ie. it wants the application to downgrade its database.

I don't want to handle this case, though I would like to notify the user somehow that there exists a newer version of my application (which she apparently had installed previously) and that's the one she should be using.

Any ideas what would be the best way to achieve this? Toast? AlertDialog (but in what context)?

有帮助吗?

解决方案

Indeed, you can call that method with a "new" version smaller than the "old" version, but when would it ever happen?

Unless you expect your users to manually reinstall your app, overwriting it with an earlier APK, there's no need to think about this.

其他提示

We have multiple active branches of our app (e.g. v1.x and v2.x), and we deliver releases internally for testing. This means a tester occasionally installs the older version over the top of the newer one.

It is a good idea to cope gracefully in this scenario (a helpful error popup, blow the database away, etc), otherwise the tester see a "Force quit" message, and then we have to look at the adb logcat logs to confirm that this was due to a version mismatch.

Initially I worried that there were other reasonable scenarios where this could happen, e.g. when Reactivating an older version in the Android Market (e.g. due to a catastrophic bug in a new version).

However, the Android docs seem to say that you can't Activate an older release:

You cannot activate a new APK that has a version code lower than that of the APK it's replacing.

So to hit this scenario you would need to rebuild the older version with a new version number before you can Activate it. IMO it is still worth coping with this scenario, as somebody could easily make this mistake at 4am while trying to backout a bad release!

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top