为什么Java Android中的super.onDestroy()在析构函数中处于首位? [英] Why does super.onDestroy() in java Android goes on top in destructors?

查看:222
本文介绍了为什么Java Android中的super.onDestroy()在析构函数中处于首位?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据析构函数中的super.onDestroy();哪个逻辑排在最前面?例如:

According to which logic does super.onDestroy(); in destructors goes on top? For example:

protected void onDestroy() {        
    super.onDestroy();
    releaseMediaPlayer();
}

而不是:

protected void onDestroy() {        
    releaseMediaPlayer();
    super.onDestroy();
}

像c ++,obj-c,pascal等吗?

Like in c++, obj-c, pascal, etc?

推荐答案

这实际上取决于您要在onDestroy中执行的操作.这就是super.onDestroy的工作(按此顺序):

It really depends on what you want to do in your onDestroy. This is what super.onDestroy does (in that order):

  • 关闭该活动正在管理的所有对话框.
  • 关闭活动正在管理的所有游标.
  • 关闭所有打开的搜索对话框

如果您放入onDestroy的逻辑与android所做的三件事有关,那么您可能必须担心顺序.否则,在大多数情况下,都没有关系.

If the logic you put inside onDestroy has something to do with those three things that android does, then you may have to worry about the order. Otherwise, and in most of the cases, it does not matter.

这篇关于为什么Java Android中的super.onDestroy()在析构函数中处于首位?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆