Krishna
Krishna

Reputation: 85

Broadcast Receiver not getting the broadcast if app is not started

I have some 2 apps all installed on a device. One of the apps catch the ACTION_BOOT_COMPLETED broadcast, does some initialization and send another broadcast (say MY_CUSTOM_BROADCAST). The second app has a broadcastreceiver (mentioned by tag in manifest) which listens for this custom broadcast. At boot time the first app receives the ACTION_BOOT_COMPLETED and sends the custom broadcast successfully. But my second app's receiver does not seem to receive it. I tried sending the custom broadcast using "am broadcast". Even then the second app's receiver does not receive it.

Then I started the second apps's main activity and then tried sending the broadcast using "am broadcast". Then the second app's receiver successfully received it.

Can someone help me as to why my receiver is not getting the custom broadcast at boot time? I am running this on 4.0.3 (ICS).

Upvotes: 5

Views: 2832

Answers (1)

Khasm
Khasm

Reputation: 163

Apparently in Android 3.1+, apps are in a stopped state if they have never been run, or have been force stopped. The system excludes these apps from broadcast intents. They can be included by using the Intent.FLAG_INCLUDE_STOPPED_PACKAGES flag.

http://commonsware.com/blog/2011/07/13/boot-completed-regression-confirmed.html

http://developer.android.com/sdk/android-3.1.html#launchcontrols

Also, I think you need the Intent.FLAG_ACTIVITY_NEW_TASK flag.

Upvotes: 7

Related Questions