java.lang.RuntimeException: 将消息发送到死的线程上处理程序的处理程序 (android.os.Handler)
来源:互联网 发布:无锡行知科技专修学院 编辑:程序博客网 时间:2024/05/17 01:27
在我的应用程序中我使用 IntentService 的发送短信。
@Overrideprotected void onHandleIntent(Intent intent) { Bundle data = intent.getExtras(); String[] recipients = null; String message = getString(R.string.unknown_event); String name = getString(R.string.app_name); if (data != null && data.containsKey(Constants.Services.RECIPIENTS)) { recipients = data.getStringArray(Constants.Services.RECIPIENTS); name = data.getString(Constants.Services.NAME); message = data.getString(Constants.Services.MESSAGE); for (int i = 0; i < recipients.length; i++) { if(!StringUtils.isNullOrEmpty(recipients[i])) { try { Intent sendIntent = new Intent(this, SMSReceiver.class); sendIntent.setAction(Constants.SMS.SEND_ACTION); PendingIntent sendPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, sendIntent, PendingIntent.FLAG_UPDATE_CURRENT); Intent deliveryIntent = new Intent(this, SMSReceiver.class); deliveryIntent.setAction(Constants.SMS.DELIVERED_ACTION); PendingIntent deliveryPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, deliveryIntent, PendingIntent.FLAG_UPDATE_CURRENT); SmsManager.getDefault().sendTextMessage(recipients[i].trim(), null, "[" + name + "] " + message, sendPendingIntent, deliveryPendingIntent); } catch (Exception e) { Log.e(TAG, "sendTextMessage", e); e.printStackTrace(); Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show(); MainActivity.instance.writeToLogFile(e.getMessage(), System.currentTimeMillis()); } } } }}
ecTransact(Binder.java:351)W/MessageQueue(7180): at dalvik.system.NativeStart.run(Native Method)
我的 SMSReceiver 位于另一个类。我怎样才能解决这个问题?
解决方法 1:
这里的问题是创建的 Toast
里面都由一个线程 IntentService
。该系统将使用 Handler
与此线程显示和隐藏关联 Toast
。
第一次 Toast
将显示正确,但当系统试图隐藏它之后, onHandleIntent
方法完成,因为将引发"将消息发送到死的线程上处理程序"的错误中至极的线程 Toast
创建的不再是有效的和 Toast
不会消失。
若要避免此应显示 Toast
发布一条消息到主线程。下面是一个示例:
// create a handler to post messages to the main thread Handler mHandler = new Handler(getMainLooper()); mHandler.post(new Runnable() { @Override public void run() { Toast.makeText(getApplicationContext(), "test", Toast.LENGTH_SHORT).show(); } });
阅读全文
0 0
- java.lang.RuntimeException: 将消息发送到死的线程上处理程序的处理程序 (android.os.Handler)
- Android学习—— Handler 的消息发送,在新的线程处理消息
- 单线程程序处理消息的方式!
- 下面的程序实现了在利用Handler在新线程当中处理消息的方法
- java.lang.RuntimeException: java.lang.NullPointerExcept的处理
- Android Handler 发送消息的线程安全问题
- Android 系列 4.11使用活动线程队列和处理程序在线程之间发送消息
- Handler发送消息后消息队列的处理
- Handler 的处理消息
- Handler的消息处理
- 子线程上的handler处理
- android Handler发送与处理消息小结
- 关于android Handler进行线程处理消息队列与线程队列线程无法停止的问题
- 【Android】Handler使用入门 处理耗时较长的程序
- Android异步消息处理Handler的使用
- 关于Android程序的java.lang.RuntimeException: Unable to instantiate activity ComponentInfo错误
- Android: 如何利用Handler处理和发送消息来实现页面刷新的功能
- 基于Handler的消息处理线程的缺点
- String、StringBuffer拼接时的时间及空间耗费的简单测试
- mvp登录
- Spring中listener监听器解析
- capsLock key to toggle between input methods [in windows] [with autohotkey]
- PHP的一个过滤敏感词或脏话的方法
- java.lang.RuntimeException: 将消息发送到死的线程上处理程序的处理程序 (android.os.Handler)
- webpack学习心得
- SmartGit(试用期30后),个人继续使用的方法
- 浅谈UML的概念和模型之UML九种图
- MSVCRTD.lib(exe_main.obj) : error LNK2019: 无法解析的外部符号 _main,该符号在函数 "int __cdecl invoke_main(void)"
- 购物车展示 CheckBox选中与否
- 添加数据给表格+隔行换色
- 第六章 多文档界面
- 会声会影提示已停止工作解决方法(修复工具)