[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是不赞成将网络连接等一系列耗时操作直接放到应用主线程进行的,推荐将这类操作放在子线程 ...
随机推荐
- Bigcommerce: 给已完成购买的客户发送一封产品评论邮件,让客户直接进行产品评论
需求说明:进入后台的Order列表,更新订单状态:Awaiting Pickup后,就会给客户发送一封希望他们能进行评论的邮件.在邮件中展示该订单下的所有产品,每个产品都有一个评论的跳转链接,点击后直 ...
- Nagios监控系统的安装
环境:centOS 6.5 X86 64位 nagios-4.08 步骤: 1. 最小化安装系统 2. 修改安全特性 关闭SELINUX SELINUX=disabled 清除iptabl ...
- SynchronousQueue、LinkedBlockingQueue、ArrayBlockingQueue性能测试
SynchronousQueue.LinkedBlockingQueue.ArrayBlockingQueue性能测试 JDK6对SynchronousQueue做了性能优化,避免对竞争资源加锁,所以 ...
- 自写jquery网页回到顶部效果,渐隐图标,引用js文件就可以
唔.进来开发需求,当网页内容草鸡多的时候,用户就须要有个button高速回到顶部,而不是自己去滚滑轮~ 原本以为比較难的说,由于上头要求所实用js来实现,哪个页面引用,哪个页面显示. 于是乎,本屌丝就 ...
- 蓝桥杯软件学院webserver,android
- hdu2222Keywords Search (特里)
Problem Description In the modern time, Search engine came into the life of everybody like Google, B ...
- c语言推断数是否是素数
这是推断数是否是素数.网络版非常.我觉得有点问题.今天一个朋友问我这个问题.我知道,今天,我把自己的代码,非常实用哦!. #include<stdio.h> #include<mat ...
- 利用Javamail接收QQ邮箱和Gmail邮箱(转)
求大神解答 Java代码: public class SendMailController { //@Autowired private JavaMailSenderImpl mailSender; ...
- 虚拟化技术学习(一)在VMware虚拟机中安装KVM
近期一直研究虚拟化技术,曾经对VMware虚拟机有一定的了解,近期突发奇想,能不能在VMware虚拟机中再装一个虚拟机呢? 那么问题就来了,首先,你须要一台电脑,vmware软件,(本人的电脑配置渣渣 ...
- GlusterFS源代码解析 —— GlusterFS 简单介绍
原文地址:http://blog.csdn.net/wangyuling1234567890/article/details/24564185 -- -- 本系列博客源代码是基于GlusterFS 3 ...