0

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);
Alex
  • 847
  • 3
  • 15
  • 23

1 Answers1

1

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.

Community
  • 1
  • 1
Cheryl Simon
  • 46,552
  • 15
  • 93
  • 82