Search code examples
androidbroadcastreceiverintentserviceandroid-intentservice

Starting an IntentService at Background with a BroadcastReceiver


I am coding an app with a IntentService which sends a Custom Intent when the job is done. Which starts some other IntentService.

In order to do that, I used a BroadcastReceiver in MainActivity.

My question is that if MainActivity goes Background, onStop, would that BroadcastReceiver still work? If it wouldn't, could I start a new IntentService with a BroadcastReceiver? I mean, since IntentService stops after the job is done, would that IntentService with BroadcastReceiver work until MainActivity onStart?


Solution

  • After you registe the broadcast receiver into the android framework, the broadcast would be sent to your app no matter your App running in the background or foreground.

    If you registe the Broadcast receiver in the AndroidMinifest.xml, even if your App has been stopped or destroyed, when the broadcast coming, the App's receiver would be load to start again.