I want show AlertDialog when i will send mail. But I have this Exception. WindowManager$BadTokenException what does it mean?

pDialog = ProgressDialog.show(MainActivity.sContext , "", "Sending Mail...", true);

    RetreiveFeedTask task = new RetreiveFeedTask();
3

There are 3 best solutions below

0
On BEST ANSWER

As far as I can understand your question the problem is that you are trying to update the UI on a different thread, and that isn't possible. The RetreiveFeedTask is probably executing on a different thread.

You have to run your code to dispay an alertdialog on the UI thread. You can do that by pasting the following code in your own code and add the code in the body of the method run().

activity.runOnUiThread(new Runnable() {
  public void run() {

  }
}
0
On

This is because your Activity is closed and you are trying to do some work with your ProgressDialog

You can handle it by using onPause method

For example

protected void onPause() {

        super.onPause();
         if ((pDialog != null) && pDialog.isShowing())
             pDialog.dismiss();
         pDialog = null;
    }
0
On

BadTokenException: You cannot display an Dialog through a Context that is not an Activity.

Use:

ProgressDialog.show(MainActivity.this, "", "Sending Mail...", true);

See: BadTokenException