toast 在IntentService中不消失
来源:互联网 发布:淘宝提醒发货不见了 编辑:程序博客网 时间:2024/05/21 14:41
表象
Service中可以正常显示Toast,IntentService中不能正常显示Toast,在2.3系统上,不显示toast,在4.3系统上,toast显示,但是不会消失。
原因
Toast要求运行在UI主线程中。
Service运行在主线程中,因此Toast是正常的。
IntentService运行在独立的线程中,因此Toast不正常。在IntentService中显示Toast
利用Handler,将显示Toast的工作,放在主线程中来做。具体有两个实现方式。
Handler的post方式实现,这个方式比较简单。
private void showToastByRunnable(final IntentService context, final CharSequence text, final int duration) {
Handler handler = new Handler(Looper.getMainLooper());
handler.post(new Runnable() {
@Override
public void run() {
Toast.makeText(context, text, duration).show();
}
});
}
0 0
- toast 在IntentService中不消失
- 在IntentService中使用Toast与在Service中使用Toast的异同
- 在IntentService中使用Toast与在Service中使用Toast的异同,intentservicetoast
- 自定义View----不消失的Toast
- 解决Toast一直不消失问题
- Android中多次弹出相同Toast提示框长时间不消失
- Service和IntentService中显示Toast的区别
- Service和IntentService中显示Toast的区别
- IntentService(或非UI线程)中使用Toast
- Service和IntentService中显示Toast的有什么区别
- 由于原本的小弹框toast在极限操作的情况下会出现悬停不消失,所以我们自定义一个toast
- Creating Toast in IntentService
- 连续弹出的多个Toast长时间显示,不消失。
- 自定义Toast工具类ToastUtil防止多次点击时Toast不消失
- Toast的正确打开方式——Toast多次显示不消失——toast显示问题
- Android之在IntentService中执行后台程序
- Toast在不同类中的使用技巧
- 在Service中使用Toast
- 人 定 胜天
- 360极速模式开启及IE渲染模式设置
- String
- Tomcat 6、7在EL表达式解析时存在的一个Bug
- 混淆模版
- toast 在IntentService中不消失
- Android gc垃圾回收研究学习
- 安卓ui线程优先级
- Android 获取屏幕尺寸与密度
- 内存管理--page.s memory.c源码分析
- LeetCode 题解(128): Majority Element
- java 单链集合实现
- Java基础---网络编程
- WIFI基本知识整理