开发中碰到的问题:token null is not valid; is your activity running?

popuwindows使用时出现异常:

  android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running

  解决方法: 
应把pop.showAtLocation(parent, Gravity.TOP,0, 0)这一句移出oncreate方法,在控件渲染完毕后再使用


    或者 延迟调用:

mHandler.postDelayed(new Runnable() {

         @Override
         public void run() {
            // TODO Auto-generated method stub
            if(popupWindow!=null){
                  popupWindow.showAtLocation(baseView, Gravity.CENTER,0,0);
               }
//
         }
      },500);

你可能感兴趣的:(problem)