看板 AndroidDev 關於我們 聯絡資訊
目標: 實做Quit功能 自動 手動 我的activity開啟順序是 A ----> B ----> C 其中B 和C 都有Quit function { A.quit = true; (A 的public static boolean) Intent intent = new Intent(this, A.class); intent.setFlag(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent) finish(); } 在A 的onResume中 { super.onResume(); if(A.quit) finish(); } 預期FLAG_ACTIVITY_CLEAR TOP會一路clear activity到A A再於onResume中finish自己, 退出整個程序 在C中Quit很正常, 一路destory到homescreen 問題是在B中Quit, 也是一路destory到homescreen, 但馬上又onCreat了"A"! 奇怪喔, 這是我哪裡弄錯了嗎? 謝謝指教喔! -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.120.186.181 ※ 編輯: jehovah 來自: 59.120.186.181 (06/19 18:26) ※ 編輯: jehovah 來自: 59.120.186.181 (06/19 18:34)
crazyma:把finish()放在onPause 06/20 09:47
jehovah:我發現create A是CLEAR_TOP flag固定的動作, 如下 06/20 13:26
jehovah:finish C->finish B->finish A->create A 06/20 13:27
jehovah:那請問應該怎樣作才能實現關閉所有activity的功能呢?? 06/20 13:28
sjrom:要terminal application? android不建議...xd 06/20 22:54
sjrom:但實作還是有可以用的 1. system.exit(0); 06/20 22:55
sjrom:2.killProcess(Process.xxx); 有點忘了..google一下. 06/20 22:55
sjrom:3. Activity.getParent 直到最top, 然後 finish()? 06/20 22:56
tomap41017:task killer真的引發很多問題QQ 06/21 00:52