Is onCreate called when an Activity is created?

Is onCreate called when creating an object of a class that extends activity? Or it is called only when the action starts, for example, over startActivity (...).

+6
source share
4 answers

To answer your question, for a class that extends activity, if you try to instantiate this action using the usual means (MyActivity ma = new MyActivity ();) the onCreate () method will NOT be called. Only if you run the Activity with the intent does the method call.

+9
source

According to the developer .android.com, an onCreate call is called when an activity starts. more details here

States of an activity

+9
source

Each action in the application goes through its own life cycle. Once and only once when an action is created, the onCreate () function is executed.

Mark Life Cycle

+2
source

I think in Android you cannot write something like this:

AClassThatExtendedAnActivity instance = new AClassThatExtendedAnActivity(); 

the only way you can use to start an activity is to send it with the intention of starting your activity.

instantiation is encapsulated in super.onCreate(savedInstanceState); when overriding the onCreate(Bundle savedInstanceState); method onCreate(Bundle savedInstanceState);

Respectfully,

0
source

Source: https://habr.com/ru/post/897631/


All Articles