Caused by: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?
是PopupWindow组件的使用问题,如果你直接在Activity创建的方法中初始化,则会有此错误
因此总结:PopupWindow必须在某个事件中显示或者是开启一个新线程去调用,不能直在oncreate方法中显示一个PopupWindow,否则永远会有以上错误
实践:
mListView.post(new showProgressViewRunnable());
private class showProgressViewRunnable implements Runnable {
@Override
public void run() {
if(isRunProgressBar){
isRunProgressBar = false;
showProgressBar();
}
}
}