Starting an Activity from a Service After Home Button Pressed Without the 5 Seconds Delay

Starting an activity from a service after HOME button pressed without the 5 seconds delay

I don't think there is a way to do it with the current APIs. I think that is how they intended it to work so that an app cannot force itself back open when the user exits with a home key press. You could add the home/ launcher intent to the filter for whatever activity it is you are trying to start. Then the user would have the choice to basically treat that app as though it is a homescreen. Then it would get launched with no delay at all whenever the user presses the home button(They'd have to select it from the list that will pop up asking which app they want to use to complete this action, but they could check always use this app to take this step away in the future.)

Delay while launching activity from service

After much digging, found out the cause of the problem. Apparently it's not a bug, it is a feature which does not allow Services or BroadcastReceivers to launch activities for up to 5 seconds after home button is pressed. No easy way to overcome this.

More info here: https://code.google.com/p/android/issues/detail?id=4536

I replaced the activity with a Window added to the window manager of the running service. This does not cause any delay.

Activity opens after delay

https://issuetracker.google.com/issues/36910222
Rather than a issue, it is most likely a framework feature which prevents app to force itself open on home button press.

There are few workarounds for this:

  1. Using pendingIntent-

    val intent = Intent(context, ActivityB::class.java)
    val pendingIntent = PendingIntent.getActivity(context, 0, intent, 0)
    pendingIntent.send()

  2. Using alarm manager to open activtiy



Related Topics



Leave a reply



Submit