Gray Shadow Gray Shadow - 5 months ago 19
Java Question

Android run multiple launch intents

In my application, I'm trying to start multiple application activities right after each other. These are other applications on the system

For example:

startActivity(getPackageManager().getLaunchIntentForPackage(packageInfo.packageName));


If I call startActivity just for lets say "Application1" then the app will start fine, but if I call startActivity twice in a row (Once for "Applicaiton1" and again for "Application2")then it will only start the second startActivity - no errors are displayed indicating that the first startActivity failed

Answer

no errors are displayed indicating that the first startActivity failed

That is because the first startActivity() succeeded.

startActivity() is asynchronous. It returns immediately, long before the activity that you requested gets started. Calling startActivity() twice in succession will start both of those activities, and the user will wind up seeing the second one, since that will be top-most on the task's back stack.

Most likely, the right answer is "don't do what you are trying to do". That being said, the only way to kinda sorta perhaps make it work is for you to call the first startActivity(), then wait until control returns to you in a future lifecycle method (e.g., onStart()) to invoke the second startActivity().