2013-07-29 56 views
0

當我按我的samsumsung星系結束按鈕S2沒有調用的onDestroy方法端應用程序不呼籲摧毀

@Override 
protected void onDestroy() { 
    // TODO Auto-generated method stub 
    super.onDestroy(); 
Toast.makeText(context, "destroy", Toast.LENGTH_SHORT).show(); 

} 
+0

什麼是「結束」按鈕 – Darussian

+0

活動應用程序菜單下的結束按鈕它位於應用程序的右側並可用於退出應用程序 – mrx10

回答

6

它不是必要的,這將在活動結束時被調用。 肯定會被調用。如果你讀的onDestroydocumentation,它說:

Note: do not count on this method being called as a place for saving data! For example, if an activity is editing data in a content provider, those edits should be committed in either onPause() or onSaveInstanceState(Bundle), not here.

如果你看到這個問題,答案here說:

onDestroy()被稱爲只有當系統資源不足(內存,CPU時間等),並決定殺死您的活動/應用程序,或者當有人調用完成()完成您的活動。

因此,當您按下該按鈕退出應用程序時,不需要調用onDestroy

+0

很高興幫助。 –

+1

我花了數小時分析線程交互,因爲在任務切換器中將我的(本地)活動劃掉時,並不總是調用onDestroy()。有時它被稱爲,但大多數時候它並不是這樣,所以我懷疑我的代碼中存在死鎖或種族。非常殘忍地立即發送SIGKILL,甚至沒有_trying_優雅地關閉活動。奇怪的是,使用ART而不是Dalvik似乎增加了'onDestroy()'調用的頻率。我第一次花了幾個小時試圖修復一個字面上是一個功能的bug。 – pauluss86