Why does my async task handler for a sqlite database trigger postExecute
immediately
I have an async class that opens up an sqlite database and if is the first
time running the database will be populated with data that takes about 10
seconds to complete. Even though there is still working being done in the
background the async task finishes immediately. I think it has something
to do with the sqlite's oncreate method possibly doing another async task
or something
class BuildDatabase extends AsyncTask<Void, Void, Void> {
ProgressDialog loading;
@Override
protected void onPreExecute() {
loading = ProgressDialog.show(ctx, "Please wait...", "Building
database, this may take a few seconds", true);
}
@Override
protected Void doInBackground(Void... params) {
// open up the database, if its the first time running the data will
// be populated
db = new SQLiteWrapper(ctx); //takes 1-10 seconds
return null;
}
@Override
protected void onPostExecute(Void result) {
Log.d(TAG,"post execute");
loading.dismiss();
}
}
The sqlite helper class main methods look like this
public class SQLiteWrapper extends SQLiteOpenHelper {
public SQLiteWrapper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
ctx = context;
}
@SuppressWarnings("deprecation")
@Override
public void onCreate(SQLiteDatabase database) {
database.execSQL(DATABASE_CREATE);
// populate our database with data from the zones file
try {
database.setLockingEnabled(false);
buildDatabase(database);
}
finally {
database.setLockingEnabled(true);
}
}
} If you're familiar with this class onCreate is only called if the
database doesn't exist.
If I manually call onCreate() within the database constructor the progress
dialog WILL show.
thoughts?
No comments:
Post a Comment