gpt4 book ai didi

java - super() 前后代码的区别

转载 作者:IT老高 更新时间:2023-10-28 20:41:18 25 4
gpt4 key购买 nike

看看下面的示例代码

@Override
protected void onPause() {
...some code here...
super.onPause();
}

@Override
protected void onPause() {
super.onPause();
...some code here...
}

当我问及代码的差异时,我并不是指执行流程,这是显而易见的。

那么这些代码之间的真正区别是什么?建议什么时候使用你的代码before super() 调用,什么时候使用你的代码after super()调用?我想在某些情况下这确实很重要。

最佳答案

您不应将任何代码放在 super.onPause() 之前,因为此方法可让系统执行正确暂停应用程序所需的操作。您要在 onPause() 回调中执行的任何代码都应该放在对 super.onPause() 的调用之后。希望这会有所帮助。

引自 Activities :

Note: Your implementation of these lifecycle methods must always call the superclass implementation before doing any work, as shown in the examples above.

关于java - super() 前后代码的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7191109/

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