Android:在注入sql时帮助创建进度条

时间:2010-11-30 16:23:39

标签: android progress-bar

我正在对sql进行一些注射,首次启动时大约有一百次。它不需要那么长时间,但我想要一个进度条,而应用程序正在注入数据。

这是我的代码,但不会出现进度条,只有黑屏。

SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
        boolean firstStart = settings.getBoolean("firstStart", true);        

        if(firstStart) {                  
         ProgressDialog dialog = ProgressDialog.show(myInject.this, "", "Please wait.", true);

            addInjection("The quick brown fox"); // about a hundred of these injections

SharedPreferences.Editor editor = settings.edit();
         editor.putBoolean("firstStart", false);
         editor.commit();

         dialog.dismiss(); //if i remove this i can see the progress dialog but wont close.
}

1 个答案:

答案 0 :(得分:1)

您将在UI Thread上以这种方式运行该操作。看看在AsyncTask

中运行'注入'代码

值得在开发者网站上阅读关于不在UI线程上运行任务的信息。