First, you should show your dialog from OnPreExecute hide it in OnPostExecute and - if necessary - modify it by publishing progress. (see here ) Now to your question: ProgressDialog.show() can take a OnCancelListener as an argument. You should provide one that calls cancel() on the progress dialog instance example: Override protected void onPreExecute(){ _progressDialog = ProgressDialog.
Show( YourActivity. This, "Title", "Message", true, true, new DialogInterface. OnCancelListener(){ @Override public void onCancel(DialogInterface dialog) { YourTask.this.
Cancel(true); finish(); } } ); } where progressDialog is a ProgressDialog member of YourTask.
First, you should show your dialog from OnPreExecute, hide it in OnPostExecute, and - if necessary - modify it by publishing progress. (see here) Now to your question: ProgressDialog.show() can take a OnCancelListener as an argument. You should provide one that calls cancel() on the progress dialog instance.
Example: @Override protected void onPreExecute(){ _progressDialog = ProgressDialog. Show( YourActivity. This, "Title", "Message", true, true, new DialogInterface.
OnCancelListener(){ @Override public void onCancel(DialogInterface dialog) { YourTask.this. Cancel(true); finish(); } } ); } where _progressDialog is a ProgressDialog member of YourTask.
This is what I found. I conducted more research my self, together with your answer given, I have made it work using your suggestion :) – javano Mar 26 at 23:07.
Javano... I tested your scenario using standard techniques, asyncTask and ProgressDialog. In my test, when the progressDialog is showing and I hit back, the progressdialog is dismissed and the background thread continues to run. I do not know why you need to call runOnUiThread.SO: show the progressDialog in onPreExecute place the long running task in doInBackground dismiss the progressDialog in onPostExecute pass the input parameters to your long running task as in: new MyAsynch().
Execute(password,inString); cancel() the asynchTask and progressDialog in onPause protected void onPause() { super.onPause(); if (asynch! = null) {asynch. Cancel(true);} if (progress!
= null){progress.cancel();} } JAL I have some code here.
Yep, this is pretty much what I was after. Managed to get it working with a interruptible progress dialogue :) – javano Mar 26 at 23:08.
Well, I had the same issue. The simplest method that worked for me is using progressDialog. SetCancelable(true).. This declares whether the dialog is cancelable by hitting the back key.. Try it and let me know if it works for you or not.
Good luck.
As per user634618's suggestions I used an onCancelListener() :D – javano Nov 2 at 8:52.
I have an AsyncTask that shows a progressDialog whilst working (it calls runOnUiThread from within doInBackground to show the progress dialog). Whilst its running I want to allow the use of the back button to cancel the operation; someone else has had this problem: BACK Button is not working ,while progressDialog is running. For what ever reason I can't reply to that thread, hence having to start another?!
I had the same idea as Sandy but this code is never called whilst the progressDialog is showing, why is this? I have implemented it inside my main activity class, does the progressDialog take the foreground focus away from my class temporarily?
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.