androidandroid-activityoncreate

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 activity is started, for example over startActivity(...)?


Solution

  • 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.