Unable to add window ,is your activity running?

Unable to add window ,is your activity running?

android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@7fd5e6 is not valid; 
is your activity running? 

Dialog在调用show或dismiss的时候,判断dialog所依赖的activity是否被销毁,否则将有可能发生Unable to add window – token android.os.BinderProxy@7fd5e6 is not valid; is your activity running?的问题。
例如:异步操作中,Activity已经退出,但是异步线程还没有执行完毕,如果此时异步线程通知主线程显示Dialog,将发生Dialog找不到可以依赖的Activity。

if (context instanceof Activity) {
    if (((Activity) context).isFinishing()) {
        return ;
    } else {
        dialog.show() ;
    }
}

你可能感兴趣的:(android,错误积累)