3

When I try to do like following code:

public class A_activity extends activity {

.........

Intent B = new Intent(this, B_activity.class);

startActivity(B);// B_activity is a progress animation

......

sendBroadcast();// use to finish B_activity

Intent C = new Intent(this, C_activity.class);

startActivity(C);// C_activity is which should be start after B_activity

.........

}

It directly jumps into C_activity, but no B_activity. After I finish C_activity, B_activity startup. It's confusing to me, how can I clear the B_activity when I jump into C_activity, or make sure the B_activity start before C_activity?

In some reason, I must start them both in A_activity, and the time of startActivity(B) and startActivity(C) is not stable, maybe very short, like 100ms.

Mitesh Vanaliya
  • 2,491
  • 24
  • 39
R.W
  • 65
  • 2

2 Answers2

1

Before answering your question...

Using activity to show progress indicator is a horrible idea. You should consider using AlertDialog instead of it.

Now the answer you want...

Unlike javascript, which is running in a single thread, when you say startActivity(B), Android simply tells ActivityManager to start an Activity, but it won't block the main thread and continue to execute following codes, that's startActivity(C) in your case.

If you insist to use B_activity as progress indicator, you should implement onActivityResult in A_activity, and call startActivity(C) once B_Activity is finished.

Hank
  • 1,318
  • 10
  • 29
0

You don't. When you call start activity, it starts immediately. Either Activity B will need to start activity C, or you can start Activity C after Activity B finishes using startActivityForResult and onActvityResult.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127