唤醒广播接收器没有接收通过sendBroadcast()发送的意图

时间:2016-03-21 04:17:38

标签: android android-intent service broadcastreceiver

我为我的Android应用程序实现了很少的服务。我的其中一项服务A_Service会检查B_Service是否已在运行,如果不是,它会通过sendBroadcast()发送广播以到达B_Broadcast_Receiver的广播接收方B_Service。< / p>

B_Broadcast_Receiver已在A_ServiceAndroid Manifest上以编程方式注册。这个电话看起来像这样:

A_Service

 
 @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        ....
        startBService()
        ...
        }
 
 public void startBService(){
     if (!ServiceCheck.isRunning(B_Service.class, getBaseContext())){
     Intent startIntent = new Intent();
     startIntent.setClass(this, B_Broadcast_Receiver.class);
     startIntent.putExtra(ServiceConstants.PARENT_ACTIVITY_NAME,    parentActivity);
     startIntent.putExtra(ServiceConstants.PARENT_SERVICE_NAME, parentService);
     //Send broadcast to start the B Wakeful BroadcastReceiver
     sendBroadcast(startIntent);
       }
    }

Wile调试我发现在onReceive()调用后应用程序永远不会到达唤醒广播接收器B_Broadcast_Receiver的{​​{1}}。

sendBroadcast(startIntent)

  
B_Broadcast_Receiver

我对为什么会发生这种情况感到困惑,因为我以与主要活动几乎相似的方法开始服务public class B_Broadcast_Receiver extends WakefulBroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Intent service = new Intent(context,B_Service.class); service.putExtra(ServiceConstants.PARENT_ACTIVITY_NAME,intent.getStringExtra(ServiceConstants.PARENT_ACTIVITY_NAME)); service.putExtra(ServiceConstants.PARENT_SERVICE_NAME,intent.getStringExtra(ServiceConstants.PARENT_SERVICE_NAME)); Log.d("Wakeful LS", "Gonna start B service"); startWakefulService(context, service); }

感谢您对此的帮助!

Android Manifest

A_Service

0 个答案:

没有答案