gpt4 book ai didi

android - Activity OnDestroy 从未调用过?

转载 作者:IT老高 更新时间:2023-10-28 22:04:14 25 4
gpt4 key购买 nike

我在我的 ListActivity 中使用以下代码

// a separate class in project
public class MyActivity extends ListActivity {
// some common functions here..
}

public class SelectLocation extends MyListActivity {

public void onCreate(Bundle savedInstance) {
// here.....
}

@Override
protected void onDestroy() {
super.onDestroy();
if (adap != null) adap = null;
if (list != null) list = null;
System.gc();
}
}

有人指导我为什么在我的代码中没有调用 onDestroy 方法?

最佳答案

onDestroy() 仅在系统资源不足(内存、cpu 时间等)并决定终止您的 Activity/应用程序或有人调用 finish( ) 关于你的 Activity 。

因此,要测试您的 code(),您可以制作一个测试按钮,该按钮将在您的 Activity 上调用 finish()

阅读更多 here .

另外,我相信您不需要在 onDestroy() 中调用所有这些东西,直到 adap 不是关键资源。即使在这种情况下,android 系统也有机制来正确处理它们。

关于android - Activity OnDestroy 从未调用过?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4449955/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com