3

This is the error log:

03-07 11:33:07.474: E/AndroidRuntime(5612): FATAL EXCEPTION: main
03-07 11:33:07.474: E/AndroidRuntime(5612): android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@45b69850 is not valid; is your activity running?
03-07 11:33:07.474: E/AndroidRuntime(5612):     at android.view.ViewRootImpl.setView(ViewRootImpl.java:567)
03-07 11:33:07.474: E/AndroidRuntime(5612):     at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:246)
03-07 11:33:07.474: E/AndroidRuntime(5612):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
03-07 11:33:07.474: E/AndroidRuntime(5612):     at android.app.Dialog.show(Dialog.java:281)

And I know it is because of bad reference, I get the context through getContext() method(The dialog is not in any activity)

So I can't use XXXActivity.this to get the right context. so what should I do?

4
  • show your code where u are creating or showing Dialog Commented Mar 8, 2013 at 8:04
  • try getApplicationContext() once. Commented Mar 8, 2013 at 8:11
  • 4
    Because there is no activity context available at that time to show dialog or dismiss dialog Fix: if(!isFinishing()){ //show your dialog dialog.show(); //dismiss your dialog dialog.dismiss(); } Commented Mar 8, 2013 at 9:38
  • @Ashok works like charmed Commented Aug 2, 2013 at 13:25

1 Answer 1

1

I also faced the same problem.I have used tab bar for this Just put getParent() instead of youractivity.this.

I hope this will help someone.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.