This probably has an answer already, I have checked but I'm not sure what to look for "Android SQLite onUpgrade do work"? I did some reading a few weeks ago and kind of put off the problem.
Basically I need to do some work when the database is upgraded! Shock horror right (going from the number of questions with onUpgrade in them I am far from alone) but in my case this means spawning various activities, it could be rather a large job.
I have learned though it is often best to go "with the grain" of Android stuff.
I don't like onUpgrade and onDowngrade These assume that upgrading is a function that has an inverse, and also that the work has a low complexity as to not take much time regardless of database size. You do not get a chance to report back to the activity to signal it to do something like "Show that spinny loading thing", you are stuck on the GUI thread (Main thread?).
I also don't think it's a big enough system to be helpful, especially if you are using database tables as an array of structures type thing. I'll expand on this if requested.
SO: Where do I do work? What is the grain I am struggling to go with regarding onUpgrade?
My solution: I plan to scrap onUpgrade and co, instead storing a revision number in my settings table (key value pairs basically), I will then compare this stored number to a constant containing the latest version, and either throw, letting the activity catch, or check to see if it is ready.
This means I can upgrade how I like, but it does mean I have to wrap SQLite in my own little layer, this isn't a bad thing, I have wrapped tables already, I don't think one ought to deal with cursors directly, but that's another thing.
Is there something I'm missing or should I just take upgrading into my own hands.
I ask not because it's a huge task, because as you can see it's not, but why does onUpgrade exist? Am I missing something?
Thanks.
Addendum: I tried going "full android" Correctly using onUpgrade (and content providers) to handle updates without blocking the main thread, are `Loader`s pointless? here but backed off because ContentProviders were overkill but that question is poorly phrased, just for the sake of full disclosure.
Addendum 2
Suppose the upgrading process requires user input, and the upgrade handler will want to start an activity, I cannot return from onUpgrade until the database is at the target version. How do I go about doing this?