Android dialogs are causing android.view.WindowManager$BadTokenException: Unable to add window

你说的曾经没有我的故事 提交于 2019-12-01 12:55:39
Umesh

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

I hope this will help.

the activity object must be the activity that is currently shown on the screen. If it's something that was already paused or not build show yet it will give this error.

see here the answer for ActivityGroup.

For child activity of a ActivityGroup, we cannot be sure that it always exist and live when we use the Context in the child activity such as PrompDialog. For example:

mPromptDialog = new LoginPromptDialog(this);//this is used as Context
//But when we use this context it may be destroyed.
//So this is the parent instance
mPromptDialog = new LoginPromptDialog(this.getParent());

preference: http://www.cnblogs.com/kaima/archive/2011/08/04/2127813.html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!