Unable to add window -- token null is not valid

Unable to add window -- token null is not valid

分类: Android   891人阅读  评论(0)  收藏  举报

如果在 onCreate 中创建该问题,就会报如上异常

【如果activity已经finish掉了。在handlerMessage中调用的时候 也会报异常】

解决办法:在onCreate中执行:

[html]  view plain copy
  1. mHandler.sendEmptyMessageDelayed(SHOWWINDOW, 200);    
[html]  view plain copy
  1.   private Handler mHandler = new Handler()  
  2.     {  
  3.         public void handleMessage(Message msg)  
  4.         {  
  5.             switch (msg.what)  
  6.             {  
  7.                 case SHOWWINDOW:  
  8.                     popupWindow = new PopupWindow(popView,  
  9.                         LayoutParams.FILL_PARENT,  
  10.                         LayoutParams.FILL_PARENT);  
  11.                     popupWindow.showAtLocation(popView,  
  12.                         Gravity.BOTTOM,  
  13.                         0,  
  14.                         0);  
  15.                     Log.debug(TAG,  
  16.                         "init popupWindow and showing!");  
  17.                     break;  
  18.                 case ClOSEWINDOW:  
  19.                     if (popupWindow != null)  
  20.                     {  
  21.                         popupWindow.dismiss();  
  22.                     }  
  23.                     Log.debug(TAG,  
  24.                         "close popupWindow and destory!");  
  25.                     break;  
  26.             }  
  27.         }  
  28.   
  29.   
  30.     };  

你可能感兴趣的:(android)