0

I am displaying a FragmentDialog F. I would like to dismiss it if the response from server is positive. I use AsyncTask to make a request after user click OK on the F. I cannot dismiss a window immediately because I have to wait for response from server.

I see two solutions:

  1. Dismiss dialog and display again.
  2. Try to hide a Fragment using fragment manager by tag.

What is better solution? Is there canonical way to do it?

  1. Let's assume the following situation: I have a button B. If user clicks B then send a request to the server. I am going to wait for a response so I show ProgressDialog P. When resposne arrived I would like to show DialogFragment. I have two doubts:

3a) What if user is very fast: click B -> click B -> showProgressDialog P `. I mean, user clicked twice very fast. He managed do it because he had done it before ProgressDialog appeared ( He triggered two events).

I am not sure whether a such scenario is possible. If not, please convince me.

3b) I want to commit to FragmentManager when AsyncTask is completed to show FragmenDialog. But, how to? I don't know state of Activity!

2 Answers2

0

Just dismiss your FragmentDialog F as soon as the user hits OK. And then show a progress dialog for the duration your AsyncTask is running.

See this answer to know how to show and dismiss progress dialog : progressDialog in AsyncTask

Community
  • 1
  • 1
Abhishek Jain
  • 3,562
  • 2
  • 26
  • 44
0

If you are using a custom DialogFragment class, use that AsyncTask inside of it and on onPostExecute just dismiss it if the results is the desired one.

If you are not using a custom class, just create one to use Async task inside it.

Gabi
  • 667
  • 1
  • 7
  • 17