Q:

Android: Rerun Database onCreate() if it fails

Because of some poor decisions, I am stuck with an onCreate() in my SQLiteOpenHelper class that can run for up to 5 minutes. The user could turn off his phone, or force close the app during this process, meaning my onCreate() will be canceled prematurely. If that is the case - I need the database to be wiped and onCreate() rerun. How can I do this?

A:

Just create your tables in onCreate() and initialise the data in another Service or background thread.
In that background thread, call beginTransaction() on your SQLiteDatabase object before you initialise the data. Then call setTransactionSuccessful() and endTransaction() when it has finished.
Keep a flag in SharedPreferences so you can check if this initialisation has already happened or not

