码迷,mamicode.com
首页 > 移动开发 > 详细

Android学习:UI线程规则+经典异常

时间:2015-02-13 16:37:31      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:thread   优化   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的那个线程才能对其进行修改。


Android学习:UI线程规则+经典异常

标签:thread   优化   android   ui   

原文地址:http://blog.csdn.net/u013628152/article/details/43794813

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!