In Main UI
:
- Create a dialog without a cancel button
- Start
AsyncTask
which in turn starts aHttpURLConnection
in thedoInBackground()
After about 10 seconds the following is started in the
Main UI
thread via apostDelayed
Runnable
Check if the Dialog has been cancelled, which would indicate a finished
HttpURLConnection
/doInBackground()
If it is not cancelled, add a cancel button with a oncancelcallback to the dialog, and the oncancelcallback will trigger some code which should be able to cancel the
HttpURLConnection
.My problem is that while the
AsyncTask
is running itsdoInBackground()
, when the cancel button appears on in the dialog and is pressed, the oncancelcallback won't excute its code while thedoInBackground()
is still doing itsHttpURLConnection
stuff. It will wait for thedoInBackground()
to finish and then execute its code, which obviates its purpose.