Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 386
Lijun Lou Avatar asked Mar 09 '26 16:03

Lijun Lou


1 Answers

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.

like image 138
Umesh Avatar answered Mar 11 '26 07:03

Umesh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!