java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
来源:互联网 发布:淘宝代销好还是自销好 编辑:程序博客网 时间:2024/06/05 15:51
java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
Worker threads are meant for doing background tasks and you can't show anything on UI within a worker thread unless you call method like runOnUiThread. If you try to show anything on UI thread without calling runOnUiThread, there will be a java.lang.RuntimeException
.
So, if you are in an activity
but calling Toast.makeText()
from worker thread, do this:
runOnUiThread(new Runnable() { public void run() { Toast toast = Toast.makeText(getApplicationContext(), "Something", Toast.LENGTH_SHORT).show(); }});
The above code ensures that you are showing the Toast message in a UI thread
since you are calling it inside runOnUiThread
method. So no more java.lang.RuntimeException
0 0
- 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.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.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.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.prepare()
- 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.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.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.prepare()
- java.lang.RuntimeException:Can't create handler inside trhead that has not called Looper.prepare
- php 中的常量
- uva993
- JQuery入门经典
- 产品经理面试题整理
- ES6 getter and setter
- java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
- 使用Adb shell command直接送key event給Android
- HDU 1074Doing Homework(状压dp)
- Windows SVN 搭建小结
- Tomcat 9.0安装配置
- 0311-HTML中的p,h,hr,br标签以及注释
- 多线程同步问题
- 最简单的迷宫求解
- spring之控制反转AOP