如果接口需要执行网络交互或者其他耗时操作,则需要检查调用者是否将接口使用在主线程,该方法可以进行检测。
private void ensureNotOnMainThread() {
Looper var1 = Looper.myLooper();
if (var1 == Looper.getMainLooper()) {
IllegalStateException var2 = new IllegalStateException(“calling this from your main thread can lead to anr”);
throw var2;
}
}
检查接口是否用于主线程
最新推荐文章于 2021-12-15 21:46:34 发布