I am loading a database without problems in a SQLiteOpenHelper>>onCreate(SQLiteDatabase)
method.
However, when I try to wrap the loading of the datab
I would do this:
private ProgressDialog progressDialog;
private Handler handler;
public yourConstructor(Context context){
progressDialog = new ProgressDialog(context);
progressDialog.setMessage("wait");
progressDialog.setCancelable(true);
handler = new Handler();
}
@Override
public void onCreate(SQLiteDatabase db) {
progressDialog.show();
new Thread(new Runnable() {
@Override
public void run() {
//your bd access here
handler.post(new Runnable() {
@Override
public void run() {
progressDialog.cancel();
}
);
}
}).start();
}
You haven't shown us where you're closing the db
so I'm going to assume you're closing it soon after:
new LoadDBTask(context, db, progressDialog, alertDialog).execute
(new Integer[] {scriptId});
I.e. in your calling class and this is most likely where your error lies. Move the DB closing statement to the onPostExecute
method and that should solve your issue.
Of course, you will have to override onPostExecute
in LoadDBTask
to do this. Remember that AsyncTask
is asynchronous and as such it will not block at the new LoadDBTask
statement I mentioned.