Android学习:UI线程规则+经典异常
一:看程序
二:可以创建一个新的线程执行阻塞部分
new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(50000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
});
三:现象
点击button2,不会影像button1,button1继续移动。
四:规则
There are simply two rules to Android‘s single thread model:
(1)Do not block the UI thread.不要阻塞UI线程
(2)Do not access the Android UI took it from outside the UI thread.
不要在UI线程之外的其他线程中,对视图中的组件进行设置。
经典异常:
Only the original thread that created a view hierarchy can touch its views.
只有创建view的那个线程才能对其进行修改。
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。