Starting Activities in a looping chain
I have three Activities, which are started in a chain. ActivityA starts ActivityB, which then starts ActivityC. I also have an Application object.
ActivityA starts ActivityB with (this snippet is actually in an anonymous class, so it needs getApplicationContext()
instead of this
).
startActivity(new Intent(getApplicationContext(), ActivityB.class));
ActivityB starts ActivityC with
startActivity(new Intent(this, ActivityC.class));
In ActivityC, if the user wants to go back to ActivityA, 开发者_如何学Che will click a Button that invokes
startActivity(new Intent(getApplication(), ActivityA.class));
My question is, is this the correct way to do this while avoiding memory leaks?
It could be, but I recommend to use
android:launchMode="singleTop"
in your manifest for your activities.
And, generally speaking, don't forget activties are stacked by android already, but you right, sometimes this stacking mechanism isn't flexible enough.
Stéphane
精彩评论