簡體   English   中英

后退按鈕關閉兩個活動?

[英]Back button closes TWO activities?

解決了!

我的活動堆棧看起來像這樣,原諒粗略的圖表!

A-->B-->C
    '-->D

如果我按下活動B后退按鈕,我會按預期返回A
但是,如果我在活動CD按回按鈕,我將返回A而不是B 在我看來,這可能是由兩件事引起的
1)活動B在打開CD的意圖時退出
2)后退按鈕以某種方式被調用兩次?

我仔細研究了活動B中的點擊監聽器,這些監聽器啟動了期望在那里找到一個finish()調用的意圖,但沒有。
我還檢查了活動CDonBackPressed()方法,看看我是否手動打開活動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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM