[Android]Can't create handler inside thread that has not called Looper.prepare()
更新是由于在新的线程来打开UI只有一个错误。子线程更新主线程UI需要使用Handler.
还有比如今天出现以下错误。码,如以下:
send.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
new Thread(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(), "主线程中UI", Toast.LENGTH_SHORT).show();
}
});
}
});
Toast.makeText(getApplicationContext(), "主线程UI", Toast.LENGTH_SHORT).show();
都是这句话惹的祸。
把上面这行代码也通过处理放进handler之后。错误就没有了。
Handler是这么定义的:
主要接受子线程发送的数据, 并用此数据配合主线程更新UI.
Handler的主要作用:主要用于异步消息的处理
Handler的执行过程:
当(子线程)发消息后,。首先,进入一个(主线程)消息队列,函数来发送消息立即返回,在主线程Handler一个在新闻删除消息队列中的一个,然后处理该消息。这样就实现了跨线程UI更新(其实在主线程中仍然完成)。
这种机构通常被用来处理通过相对耗时较长的操作,如访问网络是耗时的操作,读大的文本文件,比较费时的操作处理。
[Android]Can't create handler inside thread that has not called Looper.prepare()的更多相关文章
- 使用ClipboardManager碰到Can't create handler inside thread that has not called Looper.prepare()
直接放上我的代码.希望能给碰到相同问题的朋友提供帮助 Runnable runnable = new Runnable() { public void run() { ClipboardManager ...
- 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 ...
- 在子线程中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 ...
- Can’t create handler inside thread that has not called Looper.prepare()
1)在Android 2.3以前,为防止ANR(Application Not Responding),Google是不赞成将网络连接等一系列耗时操作直接放到应用主线程进行的,推荐将这类操作放在子线程 ...
随机推荐
- poj 3278 Catch That Cow (bfs搜索)
Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 46715 Accepted: 14673 ...
- poj 2166 构造
一个看了解题报告才能想明白的题目,第一点比较容易想明白,就是每次把1交换到堆顶之后如果能够换到最后面的位置那么一定是最优的,但是怎么实现这个没有想明白. 题解的那种构建方法,及从2开始插入,是可以保证 ...
- HDU 1226 超级密码 (搜素)
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1226 题意简单,本来是一道很简单的搜素题目. 但是有两个bug: 1.M个整数可能有重复的. 2.N可 ...
- TopCoder中插件的用法
今天弄了一下TopCoder的插件,发现真的很好很强大,插件的下载地址为 : http://community.topcoder.com/tc?module=Static&d1=applet& ...
- Coreseek:indexer crashed不解之谜
前两天浩哥让我再把Coreseek的索引再做一次,由于需求那边有点变化,要把索引的公司名字显示出来,就在配置文件中面加入了sql_field_string:字符串字段.. 这个属性特别好用,由于它不仅 ...
- MySQL外键约束OnDelete和OnUpdate的使用
On Delete和On Update都有Restrict,No Action, Cascade,Set Null属性.现在分别对他们的属性含义做个解释. ON DELETE restrict(约束) ...
- HDOJ 5276 YJC tricks time multimap
multimap的使用 YJC tricks time Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/262144 K ...
- Ubuntu12.04下载Repo
操作系统:Ubuntu12.04LTS 64bit "#"号后面表示凝视内容 $cd ~ #进入下载文件夹 $mkdir bin #创建bin文件夹用于存储Repo脚本 $PATH ...
- 《循序渐进Oracle》部分笔记
1.不要用户名/密码 直接/as sysdba 是操作系统认证方式,改变安全方式 sqlnet.ora 里SQLNET.AUTHENTICATION_SERVICES=(NTS)表示启动操作系统认证; ...
- win7提示“ipconfig不是内部或外部命令”
进入windows环境变量设置->系统变量,找到path,添加C:\Windows\SysWOW64,或者c:\windows\system32