1

I would like to send out an update of my apk, but i did some database changes which will make the app crash.

So the user has to uninstall and then reinstall it. Is there a way to deploy an apk so this is done automatically.

Or clearing the app data of the previous installation.

4 Answers4

2

You can provide the onUpgrade() method and then you can execute alter table SQL see: http://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html, this requires you to change the database version number so it can be detected when the app starts. If your schema is really different and you want to save the existing data then you should copy the data to a temporary table, drop and create the schema and copy it back again.

EdChum
  • 376,765
  • 198
  • 813
  • 562
  • im using greenDAO, there i have an option to increment the schema version. hopefully that will just work magically. ill give it a try since the app is in beta anyways. –  Apr 08 '12 at 19:08
  • this is the best practice and the database version number is there for a reason so you should use it and follow convetion, good luck. – EdChum Apr 08 '12 at 19:09
0

No people will ignore/not read any instructions you give in the "what's new" section and you cannot do this automatically.

You should upgrade your database gracefully within the app. The OpenHelper class provides all the functionality you need to do this.

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

Kuffs
  • 35,581
  • 10
  • 79
  • 92
0

As other answers indicated you should rather overwrite the onUpate() method for a flawless user experience. Reinstalling and cleaning up is well... something like 1980 style to me and the way Android is designed I hardly doubt it's supported.

So to answer the original question no I don't think it is possible to manage applications via another applications. Though my lack of knowledge of any methods performing this task is not a proof I think it's more a question of the underlying structure.

Android is a a unix based system and every application is registered as a user in this system. The user rights are very well set in this environment meaning another user (application) can not easily access data of other applications and therefore injecting/hijacking/optimising the code. An exception is e.g. external storage like SD cards. Here every application with the right permissions can troll around as they like.

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.

Community
  • 1
  • 1
nuala
  • 2,681
  • 4
  • 30
  • 50
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.

andoni90
  • 1,066
  • 2
  • 12
  • 30