作者dwadefans (wade)
看板AndroidDev
標題[問題] Activity 回 Fragment
時間Sat Mar 12 12:50:31 2016
我目前遇到的問題是
我在Fragment頁面 進入兩個Activity
F = Fragment
A = Activity
B = Activity
F --> A --> B
在B頁面Activity點選某按鈕後要回到F(Fragment)
但是我需要清除A和B的
以下是Code:
Intent intent = new Intent(B.this, F.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
但是似乎不可行,想請問如果是各位會怎麼做?
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 219.69.123.238
※ 文章網址: https://webptt.com/m.aspx?n=bbs/AndroidDev/M.1457758233.A.D78.html
※ 編輯: dwadefans (219.69.123.238), 03/12/2016 12:51:19
1F:→ corrupt003: 直接在B開啟fragment不就好? 03/12 13:00
2F:→ corrupt003: Fragment是綁定Activity的,不能只開fragment 03/12 13:01
3F:→ mshockwave: 把A, B都設定noHistory如何? 03/12 13:50
4F:→ mshockwave: 在A, B的manifest那邊設定android:noHistory=true 03/12 13:51
5F:→ s901301: 不建議設定noHistory來達到此需求, 除非有額外特殊需求 03/12 16:16
6F:→ s901301: 若想要從B回F去,且要清除A跟B,就要把它們A,B finish 03/12 16:17
7F:→ s901301: A -> B 時要將A finish,B -> F 時將B finish 03/12 16:17
8F:→ s901301: ..... 03/12 16:17
9F:→ s901301: startActivity(intent); 03/12 16:17
10F:→ s901301: B.this.finish(); // 同理A -> B 也是 03/12 16:18
11F:→ dwadefans: 好的 我最後使用finish的方式 只留一個Activity :D 03/13 19:57