嗨开发人员,
问题:
我的应用中有 5 个活动;我想让他们的行为是这样的:
我尝试了什么:
A -> C(新建一个)
Intent intent = new Intent(getApplicationContext(),
C.class);
startActivity(intent);
A -> B (新建一个)
Intent intent = new Intent(getApplicationContext(),
B.class);
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent);
B -> C (新建一个)
Intent intent = new Intent(getApplicationContext(),
C.class);
startActivity(intent);
C -> D(我想使用现有的堆栈)
Intent intent = new Intent(getApplicationContext(),
D.class);
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);
C -> E(我想使用现有的堆栈)
Intent intent = new Intent(getApplicationContext(), E.class);
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);
D -> C(我想使用现有的堆栈)
@Override
public void onBackPressed() {
Intent i = new Intent(getApplicationContext(), C.class);
i.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
this.overridePendingTransition(R.anim.right_to_left_a,
R.anim.right_to_left_b);
startActivity(i);
}
E -> C(我想使用现有的堆栈)
@Override
public void onBackPressed() {
Intent i = new Intent(getApplicationContext(), C.class);
i.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
this.overridePendingTransition(R.anim.right_to_left_a,
R.anim.right_to_left_b);
startActivity(i);
}
这不起作用,因为堆栈中的活动排列不正确。
问题是当按下返回键时我不知道如何从 C 转到 B 或 A,现在当我在 C 中按下返回键时,它转到 D 或 E!
这正是我想要的:
A->B when a button pressed,create new B
B->A when back key pressed,finish B
A->C when a button pressed,create new C
C->A when back key pressed,finish C
B->C when a button pressed,create new C
C->B when back key pressed,finish C
C->E when a button pressed,create new E if not exist otherwise use existing one
E->C when back key pressed,use existing one
C->D when a button pressed,create new D if not exist otherwise use existing one
D->C when back key pressed,use existing one