简体   繁体   中英

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

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 (eg, onStart() ) to invoke the second startActivity() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM