Different flow in the Android Activity Stack?
I have a set of activities A, B, C.
The user can go A->B->C->B->C->B. I don't want B and C to be repeating like this. Is there any intent flag I can set to limit this to A->B->C so that 开发者_如何转开发the user doesn't have to press the back button many times?
Thank you
Use FLAG_ACTIVITY_REORDER_TO_FRONT
.
Add following attribute to your AndroidManifest.xml. You should add this attribute to each activity's block, which you want to initialize only once and preserve it's state during application lifetime:
android:launchMode="singleTask"
And use following sample of code to switch between activities:
Intent i = new Intent(C.this, B.class); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(i);
You also can use Intent.FLAG_ACTIVITY_REORDER_TO_FRONT, but launchMode should be set to "singleTask" too.
精彩评论