问题
Is there any background worker in android! I used progress dialog in this
but no resolve for this suggested. I need to show a wait dialog and after my process end, do other process.
I used AsyncTask suggested in this topic but my progress dialog not show immediately yet !!
回答1:
Try this:
class myAsyncTask extends AsyncTask<Void, Void, Void> {
Context context;
myAsyncTask(Context context) {
this.context=context;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
//Do stuff that you want after completion of background task and also dismiss progress here.
}
@Override
protected void onPreExecute() {
super.onPreExecute();
//create and show progress dialog here
}
@Override
protected Void doInBackground(Void… arg0) {
//background task here
return null;
}
}
and execute like this:
myAsyncTask myWebFetch = new myAsyncTask();
myWebFetch.execute();
Hope it Helps!!
来源:https://stackoverflow.com/questions/17969415/is-there-background-worker-in-android-i-used-asynctask-suggested-in-this-topic