HI開發商,活動行爲我怎麼能做出這樣的
問題:
我在我的應用程序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);
Ç - > d(我想使用存在於堆棧)
Intent intent = new Intent(getApplicationContext(),
D.class);
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);
Ç - > 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);
}
ë - > 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!
這是確切的事情I WANT:
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
http://developer.android.com/guide/components/tasks-and-back-stack.html。 A到B到C到D或A到B到C到E.現在通過在後退時按回車鍵清除回E到C。 D到C到B到A – Raghunandan
當您從A到B並按下後退按鈕時,活動B從堆棧中彈出並銷燬。以前的活動堆棧即A需要關注。 A到B到C後面按C鍵,你可以通過清除堆棧去A。 – Raghunandan
謝謝拉古南丹,你能告訴我用編程方法清除後臺的確切方法嗎?我的問題是D和E coz它們在堆棧中,但當按下回車鍵時C –