开发者

Is onCreate called when an Activity object is created?

Is onCreate() called when a class object that extends Activity is created? Or is it only called when an activit开发者_开发技巧y is started, for example over startActivity(...)?


To answer you question, for a class that extends activity, if you try to instantiate that Activity by normal means ( MyActivity ma = new MyActivity(); ) the onCreate() method WILL NOT be called. Only if you start the Activity with an intent will the method be called.


According to the developer.android.com the onCreate get called when activity is started. see details here

Is onCreate called when an Activity object is created?


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

Check this Activity Life Cycle


i think that in Android , you cant write something like this :

AClassThatExtendedAnActivity instance = new AClassThatExtendedAnActivity();

the only way that you can use to launch an activity is passing with an intent to start your activity .

the creation of the instance is encapsulated on the super.onCreate(savedInstanceState); when you override the method onCreate(Bundle savedInstanceState);

Regards ,

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜