线程内部广播接收器Android

Vip*_*ahu 2 multithreading android broadcastreceiver looper

我得到一个DownloadManager.ACTION_DOWNLOAD_COMPLETE广播,我需要提取zip文件并填写数据库我已编写代码来完成我的工作.但我必须启动Thread来处理文件提取和插入到数据库.

我知道一个线程无法在广播接收器内启动.如果有任何身体遇到问题请建议解决方案..因为我的工作需要时间插入所以我不想等待并坚持下去.

我在广播接收器中运行线程时遇到异常

编写此代码也不适用于广播接收器

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);
        }
    }
Run Code Online (Sandbox Code Playgroud)

注意 - 没有异常或错误通过,并且在调试时没有在DDMS中启动任何Intentservice
};

Com*_*are 5

步骤#1:编写一个IntentService"处理文件提取和插入数据库"的工作.

步骤#2:startService()onReceive()您的呼叫BroadcastReceiver中将控制权传递给IntentService.