[英]Back button closes TWO activities?
解決了!
我的活動堆棧看起來像這樣,原諒粗略的圖表!
A-->B-->C
'-->D
如果我按下活動B
后退按鈕,我會按預期返回A
但是,如果我在活動C
或D
按回按鈕,我將返回A而不是B
在我看來,這可能是由兩件事引起的
1)活動B
在打開C
或D
的意圖時退出
2)后退按鈕以某種方式被調用兩次?
我仔細研究了活動B
中的點擊監聽器,這些監聽器啟動了期望在那里找到一個finish()
調用的意圖,但沒有。
我還檢查了活動C
和D
的onBackPressed()
方法,看看我是否手動打開活動A ......但我沒有。
這是活動A
的onResume方法
protected void onResume() {
super.onResume();
screenOn(SCREEN_ON_DURATION);
mWakeLock.acquire();
}
這是我開始意圖C和D的方式
Bundle info = new Bundle();
info.putString("classId", ""+classId );
Intent intent = new Intent(Notebook.this, StudentChooser.class);
intent.putExtras(info);
Notebook.this.startActivity(intent);
有人可以幫忙嗎?
編輯:我在onUserLeaveHint()中發現了finish(),這就是問題所在!
The reason may be that you are using finish() in your previous activity,For example
A->B->C
Intent intent = new Intent(B.this, C.class);
startActivity(intent);
finish();
finish() is destroying B activity hence the control is going on activity A on back button
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.