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

前端 未结 3 1747
青春惊慌失措
青春惊慌失措 2021-01-16 04:48

I have putted my activities in childview and now I cannot display dialogs from my activities and adapters. In my logCat i\'m getting

04-11 12:39:59.823: E/A         


        
相关标签:
3条回答
  • 2021-01-16 04:52

    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

    0 讨论(0)
  • 2021-01-16 05:05

    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.

    0 讨论(0)
  • 2021-01-16 05:11

    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.

    0 讨论(0)
提交回复
热议问题