How can i use AsyncTask Class to showing dialog when execute a task???
class TestAsynTask extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
ProgressDialog.show(???, null, null);
super.onPreExecute();
}
@Override
protected Void doInBackground(Void... params) {
// TODO Auto-generated method stub
return null;
}
}
Assuming that
TestAsyncTaskis an inner class to anActivity, then you can use the activity name.thisto get the context. If TestAsyncTask is not an inner class, then you will want to pass an instance of yourActivityinto the constructor so that you can provide it as theContextto theProgressDialog.show()method.Here is an example of the inner class method:
You will notice that you should save off the
ProgressDialogto a instance variable in theonPreExecute()method and callcancel()on it in theonPostExecute()method.The other approach looks similar: