-4

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

mystery
  • 153
  • 1
  • 1
  • 14

2 Answers2

2

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.

WarrenFaith
  • 57,492
  • 25
  • 134
  • 150
Panther
  • 8,938
  • 3
  • 23
  • 34
0

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

Vito
  • 1,414
  • 1
  • 13
  • 22