【发布时间】:2012-09-27 10:22:06
【问题描述】:
我得到一个 DownloadManager.ACTION_DOWNLOAD_COMPLETE 广播后,我需要提取 zip 文件并填充数据库我已经编写了代码来完成我的工作。但是我必须在这里启动线程来处理文件提取并插入数据库。
我知道在广播接收器中无法启动线程。如果任何机构遇到问题,请提出解决方案..因为我的工作需要时间插入,所以我不想等待并坚持下去。
在广播接收器中运行线程时出现异常
编写此代码在广播接收器中也不起作用
BroadcastReceiver onComplete = new BroadcastReceiver() {
public void onReceive(Context ctxt, Intent intent) {
/*
* check status message whether the last queue is successful and
* completed and then stop self
*/
if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(intent.getAction())) {
Intent mIntent = new Intent(downloadmanager1.this, DBService.class);
mIntent.putExtra("messenger", new Messenger(mHandler));
mIntent.putExtra("enqueue", enqueue);
ctxt.startService(mIntent);
// ctxt.startService(mIntent);
}
}
注意 - 没有异常或错误发生,并且在调试时在 DDMS 中也没有启动任何 Intentservice
};
【问题讨论】:
标签: android multithreading broadcastreceiver looper