Only the original thread that created a view hierarchy can touch its views

Only the original thread that created a view hierarchy can touch its views.

有时在更新UI时,会报这个错:Only the original thread that created a view hierarchy can touch its views.

在修改UI时需要自己添加一个新的线程,不然的话会阻塞UI主线程,所以只需要我们把代码放到我们自己添加的线程中就可以了,但这里需要注意的是,需要把代码放到我们所创建的线程Hander中,别且Hander是被抛出的。不然的话有可能还会报同样的错误。但是我不知道在线程中创建的Hander和被发送出的Hander有什么区别?

 

 

还有在平时使用时,会忽略一个重要的问题就是。Hander必须在主线程中生成,否侧还是会报同样的错误!

在非本Activity中使用Hander时,一定要注意,我们所引用的Hander对像是否是在Activity中创建生成的,如果不是的话。还会报同样的错误。