简体   繁体   中英

How could I start the startActivity() before startActivityForResult()

When I execute the code the startActivity() is called only after the startActivityForResult() is over. How can I start the startActivity() first? I tried with threads but I didn't succeeded.

   // Splash Correct
   Intent correct = new Intent("com.quizcontest.alex.SPLASHCORRECT");
   startActivity(correct);

   Bundle b = new Bundle();
   Intent i = new Intent(StartPlaying.this, CorrectAnswer.class);
   b.putInt("p1Key", player1Score);
   b.putInt("p2Key", player2Score);
   b.putInt("rKey", round);
   i.putExtras(b);
   startActivityForResult(i, 0);

startActivity does not block. It causes something to happen in a new thread, so it will immediately execute the lines that happen after it.

It seems like you are trying to show a splash screen. See this other question related to spash screens: Android SplashScreen or this example for displaying a splash screen using a dialog: http://blog.iangclifton.com/2011/01/01/android-splash-screens-done-right/

If the behavior you want is to start activity 1, and then start activity 2, the correct behavior is to start activity 1 for result. Then onActivityResult will be called when activity 1 has completed. At this point you can start activity 2.

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