Restriction of launching activities from background task for BroadcastReceiver

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Restriction of launching activities from background task for BroadcastReceiver

Feng LI
Hi there,

I was looking into the restriction on starting activities from background task for Android 10. It is clear that we cannot launch activities from background task, but what I am wondering is about the implications for BroadcastReceiver. 

If I send an explicit BroadcastIntent that targets one specific app2, and in the BroadcastReceiver of app2, what if I'm trying to launch activities while not in foreground.

My guess is that it'll just fail. But the tests show some interesting results.

I did 2 tests that targets on Android 10:

1. App1 launches a background task that will send an explicit broadcast intent to app2 from that background task (which is launched with StartForeground so that it'll keep running even no activities in foreground). App2 has a broadcast receiver that will log and launch an activity.

I can see the logs from App2 the every broadcast sent from App1 is well-received. While launching the activities failed from time to time, but not always. I can understand if the activity cannot be launched at all due to the previously mentioned restriction, but not sure why it succeeded sometimes.

2. The same setup as in 1. But I granted SYSTEM_ALERT_WINDOW permission for App1 (which an exception to the previously mentioned restriction). In this case, the broadcasts are well-received and the activities are launched successfully.

I'm a bit confused on this case as well. If the restriction of launching activities from background task includes broadcast receiver, shouldn't App2 has that permission?

Just wondering if you can help on this.


You received this message because you are subscribed to the Google Groups "android-platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit