Can’t create handler inside thread that has not called Looper.prepare()
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()的更多相关文章
- 在子线程中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 ...
- 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 ...
- 关于子线程使用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 ...
- 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 ...
- Android handler 报错处理Can't create handler inside thread that has not called Looper.prepare()
问题: 写了一个sdk给其他人用,提供一个回调函数,函数使用了handler处理消息 // handler监听网络请求,完成后操作回调函数 final Handler trigerGfHandler ...
- 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消息传递机制 ...
- 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报 ...
- 【转】在子线程中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 ...
- 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 ...
随机推荐
- jquery 实现图片跳动。提示作用
需要做几件事: 第一:样式表定义 .red { border: 2px solid #ffffff; } 第二:定义抖动函数 function shake(ele, cls, times) { var ...
- CSS-Sprite-Generator丨CSS雪碧在线生成器
http://cn.spritegen.website-performance.org/ Css Sprite Tools实现背景图片整合 http://www.onlinedown.net/soft ...
- 关于location.href几种用法的区别
常见的几种开发形式: self.location.href; window.location.href; this.location.href; location.href; parent.locat ...
- iOS用AVAudioPlayer播放m4a音频
音频文件sound.m4a放到Supporting Files目录 引用头文件 #import <AVFoundation/AVFoundation.h> 定义一个全局的属性: @prop ...
- Laravel Eloquent 的条件不等于
方法一: 使用Eloquent的where where('id', '!=' , 2) 方法二: 使用Eloquent的whereNotIn ->whereNotIn( 'id', [2]) 参 ...
- 一步步搭建自己的轻量级MVCphp框架-(一)什么是PHP框架以及MVC设计模式
PHP框架 php框架对很多新手而言可能会觉得很难攀越,其实不然 ,只要知道一个框架的流程,明白原理了,基本类似框架都可以看懂,php框架真正的发展要从php5开始了,其实php4时代就有一些框架,但 ...
- Java开发的一个简单截屏工具
//源代码 import java.awt.*;import java.awt.datatransfer.DataFlavor;import java.awt.datatransfer.Transfe ...
- 动态sql语句基本语法
1 普通sql语句可以用exec执行,如: SELECT * FROM video EXEC ('SELECT * FROM video') EXEC sp_executesql N'SELECT * ...
- jQuery之手势密码
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- JSP之Cookie
Cookie是小段的文本信息,在网络服务器上生成,并发送给浏览器,通过使用cookie可以标识用户身份,记录用户名和密码,跟踪重复等. 首先创建index.jsp: <%@page import ...