Is onCreate called when a class object that extends activity is created? Or is it only called when an activity is started, for example over startActivity(...).
onCreate is used to start an activity. super is used to call the parent class constructor. setContentView is used to set the xml.
onCreate() - called before the first components of the application starts. onLowMemory() - called when the Android system requests that the application cleans up memory.
OnCreate is only called once.
onCreate(Bundle savedInstanceState) Function in Android: After Orientation changed then onCreate(Bundle savedInstanceState) will call and recreate the activity and load all data from savedInstanceState. Basically Bundle class is used to stored the data of activity whenever above condition occur in app.
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.
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 ,
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With