I'm experiencing the problem described in this Android issue: http://code.google.com/p/android/issues/detail?id=4536
Simply put, after pressing the HOME button, android prevents services and broadcast-receivers from calling startActivity for 5 seconds.
I've also noticed that (well, theoretically), having the following permission :
"android.permission.STOP_APP_SWITCHES"
allows you to call resumeAppSwitches (which is defined in ActivityManagerService). Looking at the latest version of ActivityManagerService, this code is removed.
The question: How to launch an activity using startActivity without this 5 second delay?
When Home button is pressed, onStop method is called in your activity. So what you may do is to add finish(); in onStop method to destroy your activity. Eventually onDestroy method will be raised to confirm that your activity is finished.
Note: onDestroy() method not call after press Home Button.
Here is a solution I found.
Put your intent that you want to start immediately in a PendingIntent, then call the send() Method on it.
So instead of this
Intent intent = new Intent(context, A.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent);
just do this
Intent intent = new Intent(context, A.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); try { pendingIntent.send(); } catch (PendingIntent.CanceledException e) { e.printStackTrace(); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With