[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是不赞成将网络连接等一系列耗时操作直接放到应用主线程进行的,推荐将这类操作放在子线程 ...
随机推荐
- Linux段管理,BSS段,data段,.rodata段,text段
近期在解决一个编译问题时,一直在考虑一个问题,那就是Linux下可执行程序执行时内存是什么状态,是依照什么方式分配内存并执行的.查看了一下资料.就此总结一下,众所周知.linux下内存管理是通过虚存管 ...
- 跨平台网络通信与server编程框架库(acl库)介绍
一.描写叙述 acl project是一个跨平台(支持LINUX,WIN32,Solaris,MacOS,FreeBSD)的网络通信库及server编程框架,同一时候提供很多其它的有用功能库.通过该库 ...
- 使用WIX打包客户端程序
原文:使用WIX打包客户端程序 用WPF为客户做了个小工具,打包的时候发现VS2012居然没有安装项目了,搜了下才知道现在推荐使用WIX来打包了http://wix.sourceforge.net/, ...
- inkscape - 百度百科
http://wapbaike.baidu.com/view/1267893.htm?ssid=0&from=844b&uid=3151E6C0905477A13653132D762B ...
- .Net C# Windows Service于server无法启动,错误 193:0xc1
1.情况说明:的近期发展windows维修,当地win7系统正常.把server安装会失败. 图中的引导失败的例子.: 解决方法:执行->输入:eventvwr.msc 打开你的事件查看器 ...
- pygame系列_mouse鼠标事件
pygame.mouse提供了一些方法获取鼠标设备当前的状态 ''' pygame.mouse.get_pressed - get the state of the mouse buttons get ...
- C# WPF Datagrid的筛选
public static void SearchResult(DataGrid dg,string condition) { #region string code = string.Empty; ...
- 无法解析该名称 outlook必须处于联机,控制面板删除账户
无法解析该名称 outlook必须处于联机,控制面板删除账户
- Java EE (9) -- JDBC & JTA
Connection接口中定义了5中隔离级别常量 Connection.TRANSACTION_NONE -- 不支持事务 Connection.TRANSACTION_READ_UNCOMMIT ...
- 在Eclipse在使用JUnit4单元测试(0基础知识)
自这篇文章: http://www.devx.com/Java/Article/31983/0/page/1 我们在编写大型程序的时候,须要写成千上万个方法或函数.这些函数的功能可能非常强大,但我们在 ...