Lijun Lou
Lijun Lou

Reputation: 245

android.view.WindowManager$BadTokenException: Unable to add window

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?

Upvotes: 3

Views: 4081

Answers (1)

Umesh
Umesh

Reputation: 1609

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.

Upvotes: 1

Related Questions