I am not very clear functioning of the 'AsyncTask.
I'm trying to put a button in the ProgressDialog to cancel AsynkTask.
The problem is that when I invoke the method: runner.cancel (true); It seems that the ProgressDialog disappears. But asynkTask continues to work in the background.
I show my code:
public class AsyncTaskRunner extends AsyncTask<String, String, String> {
@Override
protected void onCancelled(String result) {
pDialog.dismiss();
super.onCancelled(result);
}
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(context);
pDialog.setCancelable(false);
pDialog.setMessage(context.getResources().getString(
R.string.pDialog));
if (codeLink == 2) {
pDialog.setButton("cancel", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
runner.cancel(true);
}
});
}
pDialog.show();
}
@Override
protected String doInBackground(String... params) {
// Here download the data.
}
@Override
protected void onPostExecute(String result) {
//Here I make the parser.
}
}
My guess:
it may be that doing it this way gate doInBackground () but OnPostExecute () is executed? if it were alkoxy how do I erase everything? Also OnPostExecute () ??