3

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)?

Marek Stój
  • 4,075
  • 6
  • 49
  • 50

2 Answers2

2

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.

Christopher Orr
  • 110,418
  • 27
  • 198
  • 193
  • 1
    Imagine this scenario. You're a power user, using my app and enjoying it. Then I'm releasing a new version which you install but don't like (eg. you think it has grown too much and become a bloatware), so you decide to manually install the apk of the old version. If I do nothing inside onUpgrade() to handle this case, user data may get corrupted or I can throw RuntimeException to prevent the app from running. Neither solution looks good to me. I know this would be a rather rare case but I would like to know the answer nevertheless :] – Marek Stój Feb 02 '10 at 20:16
  • 1
    Seems like a reasonable situation to me, however I'm not sure why you're liable for application errors in that situation - it's by far a non-standard usage scenario. I would think that a power user might expect that they'd have to do a clean install to downgrade. – Dan Lew Feb 02 '10 at 20:28
  • Daniel, I guess you're right. It's not that important to bother. I think I'll just throw RuntimeException in that case. Thanks for convincing me ;] – Marek Stój Feb 02 '10 at 20:48
  • 2
    Usually we simply erase the current incompatible database when in a situation like this. – hackbod Feb 03 '10 at 06:03
-1

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!

Dan J
  • 25,433
  • 17
  • 100
  • 173
  • Thats only true for playstore release. Every user still can install any older version of an app from a stored apk file. – Radon8472 Jun 17 '15 at 05:47