android handler looper thread
在线程中调用包含创建handler方法的时候,会报错,提示:
“need call Looper.prepare()” -- 在创建之前,调用Looper.prepare()方法来创建一个looper
但是这个包含创建handler的方法,可能在主线程中调用,也可能在子线程中调用。
在主线程中调用的时候,你给它加上looper.prepare()方法,它可能会报错,提示:
“Only one Looper may be created per thread” -- 每个线程之中,只能有一个Looper
解决的办法:
if (Looper.myLooper() == null) {
Looper.prepare();
}
其中,Looper.myLooper()方法的返回值是当前线程的Looper对象,返回的是Null的时候,则需要通过Looper.prepare()方法创建Looper
可以对照Looper类的源码查看一下,即可。
android handler looper thread的更多相关文章
- android Handler、Thread和Runnable
android里面的创建的Handler对象并不是新建一个新的线程,而是在主线程执行,主线程的消息队列中循环. java中实现一个线程有两种方法,一种是继承Thread类,一种是实现Runnable接 ...
- android handler looper
http://www.cnblogs.com/plokmju/p/android_Handler.html
- 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 ...
- Android handler 报错处理Can't create handler inside thread that has not called Looper.prepare()
问题: 写了一个sdk给其他人用,提供一个回调函数,函数使用了handler处理消息 // handler监听网络请求,完成后操作回调函数 final Handler trigerGfHandler ...
- 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报 ...
- Android Exception 13(Can't create handler inside thread that has not called Looper.prepare())
10-12 17:02:55.500: E/AndroidRuntime(28343): FATAL EXCEPTION: Timer-2 10-12 17:02:55.500: E/AndroidR ...
- 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 错误提示: 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 ...
- Android之消息机制Handler,Looper,Message解析
PS:由于感冒原因,本篇写的有点没有主干,大家凑合看吧.. 学习内容: 1.MessageQueue,Looper,MessageQueue的作用. 2.子线程向主线程中发送消息 3.主线程向子线程中 ...
随机推荐
- Linux新手笔记 svn ntfs
centos 6.4 64 笔记一.安装Apache1.使用yum命令安装Apacheyum -y install httpd2.设置开机启动Apachechkconfig --levels 235 ...
- BZOJ 1820: [JSOI2010]Express Service 快递服务( dp )
dp(i,j,k)表示在处理第i个业务, 另外2个在j,k处. 第一维可以滚动... --------------------------------------------------------- ...
- php实现分页,上一页下一页
首先学东西 要多看手册用php自带的函数 可以解决一些难解的问题 <?php /** * Created by JetBrains PhpStorm. * User: Administr ...
- html一些东东
在IE浏览器中,当input获得焦点时,点击有unselectable="on"属性的标签时,不会触发onblur事件 在 IE11 下,浏览器自作多情在 text input 组 ...
- perl post 带上请求头
my $url='https://www.zjcap.cn/business/dispatch_post.do?action=submitAdminLogin'; my $res = $ua-> ...
- C 语言中的变量为什么不能以数字打头
C 语言中的变量为什么不能以数字打头? C 语言中的变量为什么不能以数字打头? 不要告诉我编译原理书上有.我暂时看不懂. 除了下面的解释外, “假如变量名允许以数字开头的话,那么语法分析器在解析一个全 ...
- Java学习之IO字节流
字节流分为FileInputStream 和FileOutputStream package com.io; import java.io.File; import java.io.FileInput ...
- [python]通过urllib2设置代理访问网址
#!/usr/bin/env pythonimport urllib2 # change followings before useuser = 'foo'passwd = 'bar'proxyser ...
- Python 連接 MySQL
Python 連接 MySQL MySQL 是十分流行的開源資料庫系統,很多網站也是使用 MySQL 作為後台資料儲存,而 Python 要連接 MySQL 可以使用 MySQL 模組.MySQLdb ...
- 免费利用网页版谷歌翻译实现任意语言转换php版
本文源发布地址: http://ourgarden.cn/2013/07/20/%E5%85%8D%E8%B4%B9%E5%88%A9%E7%94%A8%E7%BD%91%E9%A1%B5%E7%89 ...