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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 09:47:50  来源:igfitidea点击:

Android: Is onResume always called after onCreate?

android

提问by capcom

I need to know if there is ever an instance when onResumewill be called before onCreatehas been called at least once. Thanks.

我需要知道是否有一个实例 whenonResumeonCreate在至少被调用一次之前被调用。谢谢。

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

活动生命周期中阅读更多相关信息

Activity Lifecycle

活动生命周期

回答by Wroclai

onResume()will always be calledwhen the activity goes into foreground, but it will neverbe executed before onCreate().

onResume()活动进入前台时将始终被调用,但在此之前永远不会执行onCreate()

回答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 LifecycleStarting an Activity 中阅读有关它的更多信息。

Below the complete image of Activity lifecycleincluding Fragment Lifecyclefrom android-lifecycle:

Activity 生命周期的完整图像下方,包括来自android-lifecycle 的Fragment Lifecycle

enter image description here

在此处输入图片说明

回答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 之前运行,所以你假设正确。