我有一个很大的sql数据库,所以我在非ui线程上做sql工作。但是,它似乎总是在ui线程上运行非ui线程。
/* MyDBHelper is singleton */
public class MyDBHelper extends SQLiteOpenHelper{
/* Singleton code here*/
@Override
public void onCreate(SQLiteDatabase db) {
buildDatabaseFromFile(db, "create.sql");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
buildDatabaseFromFile(db, "update.sql");
}
private void buildDatabaseFromFile(final SQLiteDatabase db, final String filePath) {
onSqlExecution = true;
new Thread(new Runnable() {
/* sql code here + callback in main ui activity */
}).start();
}
}
public class MainActivity() extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
MyDBHelper.getInstance();
}
@Override
protected void onResume() {
if (onSqlExecution)
/* new progress dialog here */
}
void callback() {
/* run on ui thread : dismiss progress dialog here */
}
}
你能帮帮我吗?感谢。