I have a custom dialog and when a button pressed it executes an async task. What i want is to dismiss dialog onpostexecute of async task. How can i do that?
Thanks in advance
I have a custom dialog and when a button pressed it executes an async task. What i want is to dismiss dialog onpostexecute of async task. How can i do that?
Thanks in advance
If you have the Async
as inner class dismiss it directly using dialog.dismiss()
where the dialog
is declared as class instance variable. If not, pass it via async constructor
and then dismiss
it on onPostExecute
.
Usually what I would do is: create the dialog on onPreExecute
and then dismiss
it on onPostExecute
, but it also depends on your need, where you are declaring it.
If you want to dismiss dialog before AsynTask finished, you can call dialog.dismiss()
in onProgressUpdate()
method of AsynTask in moment what you need. This function called in UI thread, so you will not have problems with that.
Additional info about onProgressUpdate()
function can find here: http://developer.android.com/reference/android/os/AsyncTask.html