开了线程,更新UI 一般会调用setText(),setImageView 回调到这里面来 ViewRootImpl checkThread(),checkThread()用来检测线程。
void checkThread() {if (mThread != Thread.currentThread()) {throw new CalledFromWrongThreadException("Only the original thread that created a view hierarchy can touch its views.");}}
其中的mThread在构造函数中赋值mThread = Thread.currentThread();,是主线程
public ViewRootImpl(Context context, Display display, IWindowSession session,boolean useSfChoreographer) {
//---------mThread = Thread.currentThread();
//-----------
}
而如果在子线程中更新UI,调用checkThread的时候Thread.currentThread()就是子线程,然后和mThread 不相等,就会抛出异常。