开发者

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜