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:
Using pendingIntent-
val intent = Intent(context, ActivityB::class.java)
val pendingIntent = PendingIntent.getActivity(context, 0, intent, 0)
pendingIntent.send()Using alarm manager to open activtiy
Related Topics
Read Only File System on Android
How Much Support Is There for -Webkit-Overflow-Scrolling:Touch
Tools: Replace Not Replacing in Android Manifest
Sharing Data Between Fragments Using New Architecture Component Viewmodel
How to Define a Circle Shape in an Android Xml Drawable File
Why Doesn't Logcat Show Anything in My Android
How to Handle Cookies in Httpurlconnection Using Cookiemanager
Adjustpan Not Preventing Keyboard from Covering Edittext
Share Sqlite Database Between 2 Android Apps
How to View Androidmanifest.Xml from APK File
Android - Multiple Screen Support Issue
Android: Creating Custom Preference
Android - Local Image in Webview
How to Make an App's Background Image Repeat
Creating Temporary Files in Android
How to Capture an Image and Store It with the Native Android Camera