Start an Activity from inside the execution of an `PendingIntent.getBroadcast(...)` takes too long when the process is dead

2020-03-27 android android-intent broadcastreceiver

I have the following situation in my app:

I create a notification from a secondary process with this Content Intent:

PendingIntent.getBroadcast(
    context,
    0,
    intent,
    PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_CANCEL_CURRENT
)

When the user clicks on the notification, the following code is executed:

context.startActivity(Intent(context, SomeActivity::class.java))

For some reason that is unknown to me, when the main process is dead, the white screen of the cold start (just like the one that appears when you launch the app from the home of the device) takes too long to start to be displayed.

But if I change the Content Intent to:

PendingIntent.getActivity(
    context,
    0,
    Intent(context, SomeActivity::class.java),
    PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_CANCEL_CURRENT
)

The white screen of the cold start is instantly displayed when the user clicks on the notification.

How can I make the displaying of the white screen of the cold start from within the broadcast intent instant?

Answers

Related