1)在Android 2.3以前,为防止ANR(Application Not Responding),Google是不赞成将网络连接等一系列耗时操作直接放到应用主线程进行的,推荐将这类操作放在子线程内;而Android 4.0版本开始,Google强制要求这类操作必须在子线程内进行,否则将抛出 NetworkOnMainThreadException 异常。

(2)操作UI必须只能在主线程内进行,否则报“Can’t create handler inside thread that has not called Looper.prepare()”错误。

在这里需要注意的是,Toast 也属于UI操作。

具体操作可以参考:http://jerry.hk/notes/android-thread-and-handler

Can’t create handler inside thread that has not called Looper.prepare()的更多相关文章

  1. 在子线程中new Handler报错--Can't create handler inside thread that has not called Looper.prepare()

    在子线程中new一个Handler为什么会报以下错误? java.lang.RuntimeException:  Can't create handler inside thread that has ...

  2. Android 线程更新UI报错 : Can't create handler inside thread that has not called Looper.prepare()

    MainActivity中有一个按钮,绑定了save方法 public void save(View view) { String title = titleText.getText().toStri ...

  3. 关于子线程使用Toast报错Can't create handler inside thread that has not called Looper.prepare()的解决办法

    形同如下代码,在Thread中调用Toast显示错误信息: new Thread(new Runnable(){ @Override public void run() { try{ weatherD ...

  4. Android-java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()

    章出自:luchg技术交流 http://www.luchg.com 版权所有.本站文章除注明出处外,皆为作者原创文章,可自由引用,但请注明来源,谢谢. Android-java.lang.Runti ...

  5. Android handler 报错处理Can't create handler inside thread that has not called Looper.prepare()

    问题: 写了一个sdk给其他人用,提供一个回调函数,函数使用了handler处理消息 // handler监听网络请求,完成后操作回调函数 final Handler trigerGfHandler ...

  6. Android进阶(八)Can't create handler inside thread that has not called Looper.prepare()

    Error:Can't create handler inside thread that has not called Looper.prepare() 原代码: //利用Handler消息传递机制 ...

  7. Android进阶(十六)子线程调用Toast报Can't create handler inside thread that has not called Looper.prepare() 错误

    原子线程调用Toast报Can't create handler inside thread that has not called Looper.prepare() 错误 今天用子线程调Toast报 ...

  8. 【转】在子线程中new Handler报错--Can't create handler inside thread that has not called Looper.prepare()

    在子线程中new一个Handler为什么会报以下错误? java.lang.RuntimeException:  Can't create handler inside thread that has ...

  9. Android 错误提示: Can't create handler inside thread that has not called Looper.prepare()

    Can't create handler inside thread that has not called Looper.prepare() 将 Handler handler = new Hand ...

随机推荐

  1. Log4Net(三)之记录日志到数据库

    前面两篇短文向大家介绍了如何使用log4net,以及如何将log4net记录到文本文件中.下面本文将向大家介绍如何将log4net记录到数据库中. 经过前面的介绍,我想大家对使用log4net的过程已 ...

  2. Mac 10.9 自带apache2虚拟目录设置

    花了好几天时间做这个事,终于成功,把正确的做法记录一下. 如果是第一次使用apache,可以先执行sudo apachectl start,然后在浏览器里打开http://localhost看看效果, ...

  3. JDK的安装

    安装jdk解压拷贝过来的jdk(1.6版本)压缩包 cd /usr/local/tar xzvf /tmp/jdk.tgz 修改环境变量vi /etc/profile 加入如下内容export JAV ...

  4. 关于Merge的整理--Merge的使用方法和注意事项的Demo

    上一篇文章中讲到了Merge的用法和注意事项,所以本人就想,做了一个Demo进行验证下. 一.Merge的使用 (1)activity中的onCreate方法中的setContentView(R.la ...

  5. Quartz Scheduler(2.2.1) - Working with JobStores

    About Job Stores JobStores are responsible for keeping track of all the work data you give to the sc ...

  6. HTTP - Cookie 机制

    HTTP 是种无状态的协议,即使用 HTTP 协议时,每次发送请求都会产生对应的新响应,协议本身不会保留之前一切的请求或响应报文的信息.这是为了更快地处理大量事务,确保协议的可伸缩性,而特意把 HTT ...

  7. Spring 数据源配置三:多数据源

    在上一节中,我们讲述了多数据的情况: 1. 数据源不同(数据库厂商不同, 业务范围不同, 业务数据不同) 2. SQL mapper 文件不同, 3. mybatis + 数据方言不同 即最为简单的多 ...

  8. JavaScript 参考手册

    http://www.w3school.com.cn/jsref/index.asp https://developer.mozilla.org/zh-CN/docs/Web/JavaScript

  9. win2003域控制器密码遗忘如何修改

    在公司遇到这么个事儿,员工搭建QC服务器,设置了域账户登陆系统.但忘记了登录密码,使用PE直接修改sam文件不好用.   1.使用PE进系统修改组登陆方式的账号administrator密码 需符合复 ...

  10. 有趣的hello word

    程序一 #define _________ } #define ________ putchar #define _______ main #define _(a) ________(a); #def ...