首先说说我自己的应用场景
我自定义了一个popupwindow,然后在show的时候提示了这个错,大致意思就是动画在子线程运行了
public void show() {
Activity topActivity = ActivityUtils.getTopActivity();
if (topActivity instanceof AppCompatActivity) {
showAtLocation(topActivity.getWindow().getDecorView(), Gravity.CENTER, 0, 0);
}
}
既然已经提示的这么清楚了,那我就加个Looper.getMainLooper主线程操作 ,嗯就这样可以大致解决
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
PopManager.get().show();
}
});
重点重点:接下来我出发了另一个问题,场景是:我从activityA跳转到activityB,然后我activityB有个借口,我再借口请求的时候show,在请求结束后dismiss, 然后就报了个错Unable to add window -- token null is not valid; is your activity running?
具体关于这个错,请访问https://blog.csdn.net/lovelixue/article/details/115233735
相似异常:Only the original thread that created a view hierarchy can touch its views