Android-java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
Android-java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
当我们在一个新的线程中使用android UI时,遇到这个异常
看了很多文章也还是不太清楚具体是什么原因,但是处理这个问题是很简单的,如下代码:
|
1
2
3
4
5
6
7
8
9
10
11
|
@Overridepublic void run() { //前面代码省略 Looper.prepare(); Log.i("---my tag---", "下载完成:"+downloadPath); Toast.makeText(context, fileName+"下载完成...", Toast.LENGTH_LONG).show(); Looper.loop(); } |
在使用Toast之前加一行Looper.prepare();,然后在Toast之后加一行Looper.loop();,即可实现。看了很多文章也没理解,所以这里就不误导大家了,感兴趣的自己搜搜原因。
上面代码是我自己写的文件下载功能一部分代码,完整代码可以查看:
Android-java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
Android-java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()的更多相关文章
- java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()解决办法
代码改变世界 java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.pre ...
- java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
- android Toast提示异常:java.lang.RuntimeException: Can't create handler inside thread that has not called
Toast只能在UI线程弹出,解决此问题可以在Toast前后加两行代码,如下所示: Looper.prepare(); Toast.makeText(getApplicationContext(),& ...
- 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 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 ...
- 在子线程中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 ...
- 【转】在子线程中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 ...
- 转 在子线程中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之模拟器更新底层
Android源码修改,编译后得到system.img 替换\AndroidSDK\system-images\android-21\android-tv\armeabi-v7a\目录中的system ...
- git命令(流程)
1,配置你的信息: git config --global user.name 你的名字 git config --global user.email 你的邮箱 --global 表示所有git仓库都 ...
- 对象创建型模式------Abstract Factory(抽象工厂)
1. 意图 提供一个创建一系列相关或相互依赖对象的接口,而无需指定它们具体的类.2. 别名 Kit3. 动机 假设我们要开发一款游戏,当然为了吸引更多的人玩,游戏难度不能太大 ...
- effective c++(05)(06)之c++默默编写并调用的函数
1. 当只写一个空类的时候,编译器会为他声明一个copy构造函数,一个copy assignment函数和一个析构函数.如下: 如果写下: class Empty{ }; 编译器就会实现以下代码: c ...
- 解决div布局中第一个div的margin-top在浏览器中显示无效果问题。
原味来源:http://www.hicss.net/do-not-tell-me-you-understand-margin/ 垂直外边距合并问题 别被上面这个名词给吓倒了,简单地说,外边距合并指的是 ...
- Jsp页面里引入一个javascript文件,在jsp的onclick里怎么添加脚本文件里的方法
举个简单例子:首先新建use.js文件内容:function show(){ alert("aa");} 建html文件跟use.js放同目录下: <html>< ...
- C++ 书籍
C++ 书籍 一.<深度探索C++对象模型/Inside the C++ Object Model> 二.
- 只有PD号的调起
cicsterm-> CECI -> LI-> P -> TestQuery
- java File详解
一.简介 File类是“文件”和“目录名”的抽象表示形式.因此在java语言中,File类既可以表示文件也可以表示目录. 尽管java.io定义的大多数类是实行流式操作的,而File类则不是,它没有指 ...
- Openstack安装
作者:陈沙克 Openstack发展很猛,很多朋友都很认同,2013年,会很好的解决OpenStack部署的问题,让安装,配置变得更加简单易用. 很多公司都投入人力去做这个,新浪也计划做一个Opens ...