Search code examples
androidperformanceandroid-intentserviceandroid-14

Slow intent broadcast delivery on Android 14


I have 2 services in my app that sometimes communicate with each other via broadcast intents. The time between an intent being sent and getting delivered on Android 13 is 1-2ms (tested on a Pixel 4XL). The time on Android 14 is ~500ms (tested on a Pixel 6 Pro)!

The slow intent delivery is causing a lag in my app that wasn't there before. I know about the context-registered broadcasts being queued while apps are cached as of Android 14, but this is between an actively running foreground service and an Accessibility service. Are all intents slowed down on Android 14?

Does anyone know what may be causing this performance issue?

EDIT: Upon further testing, it looks like intents are delayed 500ms when there is no activity in the foreground. There is no delay while there IS an activity in the foreground. The delay appears as soon as you leave the app, even without killing it.

So it appears that intents are slowed down even between foreground services, if there is no activity in the foreground. Is this documented?

Is there anything I can do to prevent this? I'm using a dynamically registered receiver:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
        registerReceiver(broadcastReceiverInternal, intentFilter, RECEIVER_NOT_EXPORTED);
    } else {
        registerReceiver(broadcastReceiverInternal, intentFilter);
    }

Setting it to exported does not make a difference.


Solution

  • It looks like sendOrderedBroadcast() is not affected by this background delay applied to sendBroadcast() in Android 14, so I will be using that instead.