token null is not valid; is your activity running?解决方案
2017-02-24 15:38
561 查看
问题原因:
当popwindow调用时,其依附的parentview(下面函数的第一个参数)还没渲染创建完成,即parentview所在的activity没有完成。
解决方法:
1,当activity添加到window完成后,再调用popwindow:
onWindowFocusChanged(),当window焦点变换后调,当hasFocus = true时,表示获得焦点,即activity渲染完成,window获得焦点。
2,当popwindow附在的parentview,渲染完成后,再调用popwindow:
当view渲染完成后,调用onGlobalLayout回调接口。在这里调用。
当popwindow调用时,其依附的parentview(下面函数的第一个参数)还没渲染创建完成,即parentview所在的activity没有完成。
jumpWidnow.showAtLocation( view, Gravity.BOTTOM, 0, 0 );
解决方法:
1,当activity添加到window完成后,再调用popwindow:
public void onWindowFocusChanged(boolean hasFocus) { super.onWindowFocusChanged(hasFocus); Log.d("liudezu","====="+this.getClass().getName()+":onWindowFocusChanged"); if(hasFocus){ //showPopupJumpWindow(); } }
onWindowFocusChanged(),当window焦点变换后调,当hasFocus = true时,表示获得焦点,即activity渲染完成,window获得焦点。
2,当popwindow附在的parentview,渲染完成后,再调用popwindow:
viewPager.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { // do something showPopupJumpWindow(); viewPager.getViewTreeObserver().removeOnGlobalLayoutListener(this); } });
当view渲染完成后,调用onGlobalLayout回调接口。在这里调用。
相关文章推荐
- [报错]token null is not valid is your activity running
- BUG popupwindow的使用 token null is not valid; is your activity running?
- Unable to add window -- token null is not valid; is your activity running?错误及其修改方法
- PopupWindow出现Unable to add window -- token null is not valid; is your activity running?
- - Unable to add window -- token null is not valid; is your activity running?
- PopupWindow出现Unable to add window -- token null is not valid; is your activity running?
- Unable to add window -- token null is not valid; is your activity running?
- PopWindow Unable to add window -- token null is not valid; is your activity running
- Activity has leaked window that was originally added -界面退出时未关闭对话框异常 android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running? -
- popupwindow使用之异常-Unable to add window -- token null is not valid; is your activity running?
- 开发中碰到的问题:token null is not valid; is your activity running?
- Unable to add window -- token null is not valid; is your activity running?
- unable to add window -- token null is not valid; is your activity running 错误解决办法
- bug--Unable to add window –token is not valid; is your activity running?
- view.WindowManager$BadTokenException: Unable to add window…is not valid; is your activity running?
- Unable to add window -- token android.os.BinderProxy@XXX is not valid; is your activity running?
- Unable to add window -- token android.os.BinderProxy@xxx is not valid; is your activity running
- Unable to add window — token android.os.BinderProxy is not valid; is your activity running?
- Unable to add window — token android.os.BinderProxy is not valid; is your activity running?
- Unable to add window --token is not valid; is your activity running?