Android:onResume 总是在 onCreate 之后调用吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12116096/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android: Is onResume always called after onCreate?
提问by capcom
I need to know if there is ever an instance when onResume
will be called before onCreate
has been called at least once. Thanks.
我需要知道是否有一个实例 whenonResume
会onCreate
在至少被调用一次之前被调用。谢谢。
Edit: Judging by the activity life cycle, it doesn't seem so. But I want to double check.
编辑:从活动生命周期来看,似乎并非如此。但我想仔细检查一下。
回答by Sam
onResume()
will never be called before onCreate()
.
onResume()
之前永远不会被调用onCreate()
。
Read more about it in the Activity Lifecycle
在活动生命周期中阅读更多相关信息
回答by Wroclai
onResume()
will always be calledwhen the activity goes into foreground, but it will neverbe executed before onCreate()
.
onResume()
活动进入前台时将始终被调用,但在此之前永远不会执行onCreate()
。
回答by Karthik Rk
you can refer the website for more details
http://developer.android.com/training/basics/activity-lifecycle/starting.html
您可以参考网站了解更多详情
http://developer.android.com/training/basics/activity-lifecycle/starting.html
回答by hushed_voice
I had an issue in which overridden onCreate was notgetting called. I tried debugging and logging and i found oncreate not getting called.
我遇到了一个问题,即没有调用覆盖的 onCreate 。我尝试了调试和日志记录,但发现 oncreate 没有被调用。
Turns out that i override wrong onCreate
原来我覆盖了错误的 onCreate
@Override
public void onCreate(@Nullable Bundle savedInstanceState, @Nullable PersistableBundle persistentState) {
super.onCreate(savedInstanceState, persistentState);
}
This is the correct one.
这是正确的。
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
Posting in the hope that it might help some poor soul. :)
发帖希望它可以帮助一些可怜的灵魂。:)
So the correct onCreate() will always gets called before onResume
所以正确的 onCreate() 总是会在 onResume 之前被调用
回答by ??? ???? ????
Note:This answer only an additional one to complement the accepted answers.
注意:此答案只是补充已接受答案的补充。
As previous answers say:
正如之前的回答所说:
onResume() will never be called before onCreate().
onResume() will never be called before onCreate().
Read more about it in the Activity Lifecycleand Starting an Activity.
在Activity Lifecycle和Starting an Activity 中阅读有关它的更多信息。
Below the complete image of Activity lifecycleincluding Fragment Lifecyclefrom android-lifecycle:
在Activity 生命周期的完整图像下方,包括来自android-lifecycle 的Fragment Lifecycle:
回答by android developer
the activity has its own lifecycle . just read and look at the nice graph here:
活动有自己的生命周期。只需阅读并查看这里的漂亮图表:
http://developer.android.com/reference/android/app/Activity.html
http://developer.android.com/reference/android/app/Activity.html
onResume doesn't suppose to run before onCreate , so you assume correctly .
onResume 不应该在 onCreate 之前运行,所以你假设正确。