2015-03-31 146 views
0

我想徹底退出應用程序。我嘗試了finish()android.os.Process.killProcess(Process.myPid()),但它們仍然使應用程序在後臺運行。如何完全退出應用程序

很多人都說這是不可能的,但我的銀行應用程序能夠做到這一點。當您退出該銀行應用程序時,無法在近期應用程序菜單中看到它。

有誰知道該怎麼做?

+0

你們是不是要終止該應用或從最近的應用程序菜單隱藏? – 2015-03-31 23:20:28

+1

你的意思是http://stackoverflow.com/questions/13704782/android-remove-application-from-recent-apps從最近的應用程序隱藏並不一定意味着該應用程序真的被殺害。 – 2015-03-31 23:20:44

+0

http://www.vogella.com/tutorials/AndroidLifeCycle/article.html – 2015-03-31 23:30:40

回答

4

當您退出該銀行應用程序時,無法在「最近的應用程序」菜單中看到它。

這與過程無關。進程和任務並不特別相關。

嘗試finishAndRemoveTask()(API等級21+)或者可能finishAffinity()(API等級16+),這兩種方法都在Activity上。或者,正如Thom Wiggers在評論中所建議的那樣,該應用程序可能通過android:excludeFromRecents未顯示在最近的任務列表中。

android:excludeFromRecents="true" 

爲了除去從下面代碼背景應用使用:

+1

另外,關於銀行應用程序,WindowManager.LayoutParams.FLAG_SECURE可能是我們想要的,而不是excludeFromRecents。 – 2015-03-31 23:38:49

1

爲了從最近用過清單中使用此在活動標籤去除活性。請注意,這不會從最近的應用程序中刪除應用程序。它只是從開始活動開始應用程序。

int pid = android.os.Process.myPid(); 
android.os.Process.killProcess(pid); 

Intent intent = new Intent(Intent.ACTION_MAIN); 
intent.addCategory(Intent.CATEGORY_HOME); 
startActivity(intent);