I am doing some injections to sql, about a hundred on first launch. it doesn't take that long but i want a progress bar while the app is injecting data.
This is my code but progress bar doesn't appear, only black screen.
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
boolean firstStart = settings.getBoolean("firstStart", tru开发者_如何学编程e);
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.
}
You will be running the operation on the UI Thread doing it this way. Take a look at running the 'inject' code within an AsyncTask
It's worth having a read up on the developer site about not running tasks on the UI Thread.
精彩评论