Search code examples
androidbroadcastreceiver

When does BroadcastReceiver get enabled?


If I register a BroadcastReceiver in the manifest of my app (e.g to be notified of network changes), when does it start to be notified ? At device startup ? Or does the app need to be manually launched ?


Solution

  • It starts receiving broadcasts when your device is booted completely. However, starting from Honeycomb (API Level 12), you need to launch your application at least once to make it enable for start listening broadcasts.

    In Honeycomb and above, when you install your application, the framework marks it as STOPPED_PACKAGE and does not include its broadcast receivers for listening. But once you launch your application once, such marking is removed and you are good to go :)

    As an alternate, try setting the flag Intent.FLAG_INCLUDE_STOPPED_PACKAGES to your broadcast intent in order to include those packages too which are stopped.

    For example:

    intent.setFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);