In an Activity, first open the onCreate method or class constructor?

Asked

Viewed 216 times

2

In a scenario where you have an Activity with a constructor (public, of course) and the onCreate method which is part of your life cycle. Which of the two will be executed first?

  • 2

    Do not use the Activity class constructor. Anything you think should/can do in the constructor onCreate()

  • but answering the question.. According to the siclo d life of android, will be first realized what is on onCreate.

  • @Edumachdo The builder is always called first.

1 answer

3


Think like this, if a constructor is the first "method" to be executed, before the others (even if there is the main method, in the case of JAVA), then obviously the constructor will be executed even before onCreate().

I hope I’ve helped!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.