0

当我按下三星 Galaxy S2 上的结束按钮时,它不会调用 onDestroy 方法

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

}
4

1 回答 1

6

没有必要在活动完成时调用它。onPause肯定会被调用。如果您阅读 的文档onDestroy它会说:

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.

如果你看到这个问题Activity OnDestroy never called? ,这里的答案是:

onDestroy()仅当系统资源不足(内存、cpu 时间等)并决定终止您的活动/应用程序或有人在您的活动上调用完成()时才调用。

因此,当您按下该按钮退出应用程序时,它没有必要onDestroy被调用。

于 2013-07-29T13:18:06.887 回答