Android: Is onResume always called after onCreate?

后端 未结 6 522
南旧
南旧 2021-01-30 13:17

I need to know if there is ever an instance when onResume will be called before onCreate has been called at least once. Thanks.

Edit: Judging b

相关标签:
6条回答
  • 2021-01-30 13:26

    the activity has its own lifecycle . just read and look at the nice graph here:

    http://developer.android.com/reference/android/app/Activity.html

    onResume doesn't suppose to run before onCreate , so you assume correctly .

    0 讨论(0)
  • 2021-01-30 13:30

    This is basic activity life cycle which would help you understand better

    you can refer the website for more details
    http://developer.android.com/training/basics/activity-lifecycle/starting.html

    0 讨论(0)
  • 2021-01-30 13:32

    I had an issue in which overridden onCreate was not getting called. I tried debugging and logging and i found oncreate not getting called.

    Turns out that i override wrong 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 get called before onResume

    0 讨论(0)
  • 2021-01-30 13:35

    onResume() will always be called when the activity goes into foreground, but it will never be executed before onCreate().

    0 讨论(0)
  • 2021-01-30 13:41

    onResume() will never be called before onCreate().

    Read more about it in the Activity Lifecycle

    Activity Lifecycle

    0 讨论(0)
  • 2021-01-30 13:41

    Note: This answer only an additional one to complement the accepted answers.

    As previous answers say:

    onResume() will never be called before onCreate().

    Read more about it in the Activity Lifecycle and Starting an Activity.

    Below the complete image of Activity lifecycle including Fragment Lifecycle from android-lifecycle:

    0 讨论(0)
提交回复
热议问题