vendredi 10 juillet 2015

Display Please wait while upgrading database in android

I want to upgrade my db in next update, but I've faced with problem. my upgrading is too heavy and spend 2-3 minute in device ( depends on hardware of device ) and it's contains delete some table create table and move data from old table to new table, I don't want to user see white screen while upgrading, and as database upgrading is first command that runs I can't start any activity to see please waiting or any other data.

for solving this issue i've use AsyncTask class, in onUpgrade of database i execute an asyncTask class to do my upgrading, and i can start my splash screen to notify to user that application need some time. but with this solution i lost Transactional behaviour and if device has been turned off, or application be killed my application faced with bigger problem.

I know how to run my multiple code in Transactional, but as i understand, database version has been increased and next time that I launch application database don't upgrade anymore and application don't work any more. ( because new table not exists).

I think on one solution to keep track my upgrade database and save into sharedPref and in the next launch check the value in sharedPreference and if upgrade has been complete let user to use application, else finish upgrade process.

I don't think that be a best way, so i want to ask you, is any other solution exists to upgrade database in background and if problem happened database upgrade start over again?

Thanks in advance , and thanks for your time.

PS: I know if any error happened in onUpgrade, database upgrading start over but when I move upgrading from UI thread to back thread this not happened any more, and i don't know why.

Aucun commentaire:

Enregistrer un commentaire