问题描述
我使用下面的code在我的ListActivity
I am using following code in my 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
方法不叫我的code?
any one guide me why onDestroy
method is not called in my code?
推荐答案
的onDestroy()
被称为只有当系统资源不足(内存,CPU时间等),并作出决定杀死你的活动/应用程序或当有人呼叫完成()
您的活动。
onDestroy()
is called only when system is low on resources(memory, cpu time and so on) and makes a decision to kill your activity/application or when somebody calls finish()
on your activity.
所以,来测试你的code(),你可以做一个测试按钮,将调用完成()
您的活动。
So, to test your code() you can make a test button, that will call finish()
on your activity.
了解更多here.
另外,我相信你并不需要调用所有这些东西在的onDestroy()
直到ADAP不是关键资源。即使在这种情况下,Android系统有机制妥善处置他们。
Also, I believe you don't need to call all this stuff in onDestroy()
until adap is not a critical resource. And even in that case android system has mechanisms to properly dispose them.
这篇关于活动的OnDestroy从来不叫?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!