Search code examples
androidjakarta-mailandroid-alertdialog

"android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application"


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();

Solution

  • 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() {
    
      }
    }