Flynn
Flynn

Reputation: 6211

Android Dialogs

So I am having some difficulties with Android Dialogs. All I want to do is display a dialog when a button is pressed, and then when my AsyncTask is done, dismiss it. I can't even get it to display though. Here is my code for the dialog inside my OnClick listener:

    ProgressDialog dialog = ProgressDialog.show(getApplicationContext(), "", 
                                "Loading. Please wait...", true);

My Logcat says that it is unable to add window. Here it is:

    01-21 17:44:48.044: E/AndroidRuntime(6319):     at android.app.ProgressDialog.show(ProgressDialog.java:116)

How do I get the dialog to show up?

EDIT:

The problem was that when I was getting the Context, it wasn't getting my Activity's context. So I made a variable that was set to my Activity's context and passed that in fixing it.

Upvotes: 2

Views: 482

Answers (2)

J. Maes
J. Maes

Reputation: 6892

You shouldn't use getApplicationContext() for this, several people have had problems using it. Can you use the context of your activity one way or another?

Upvotes: 1

waqaslam
waqaslam

Reputation: 68187

You should not use application's context to initialize dialog window. Instead, use getBaseContext or activity's reference by using this

Upvotes: 0

Related Questions