0

I have a class that extends Activity like so:

public abstract class AndroidGame extends Activity implements Game

This class has an onCreate() method like this:

public void onCreate(Bundle savedInstanceState) {
 // I do stuff here
}

Then I make another class that extends AndroidGame like so:

public class ScatmanNomGame extends AndroidGame {   
    // The loading screen will load all the assets of our game
    @Override
    public Screen getStartScreen() {
        return new LoadingScreen(this);     
    }    
}

Ok, so here is my question. My default start activity (in my manifest file) is set to load ScatmanNomGame first. Upon launch of my program, the Launcher activity is ScatmanNomGame. But notice that ScatmanNomGame has no onCreate() method. Will simply starting this activity (ScatmanNomGame) call it's super class's onCreate method?

Rob
  • 4,927
  • 12
  • 49
  • 54
Captainlonate
  • 4,878
  • 4
  • 25
  • 35
  • What did you observe by running this code? – user370305 Jul 24 '12 at 05:40
  • Did you try to run this program? What happens? The question you have asked can very much be answered by running the program. Just add a Log statement in `OnCreate()` of `AndroidGame` activity and run the program and you will know if it is called or not.Dont you think so..this will work ? – Abhilasha Jul 24 '12 at 05:41

1 Answers1

1

Yes, It would, Read Inheritence.
Inheritence allows object of subclass to use/access public and protected fields and methods. So, If you havent overrided any method in the subclass, and invoking the same method on the object of subclass will invoke method of superclass.

jeet
  • 29,001
  • 6
  • 52
  • 53
  • Apparently onCreate() is automatically called when an activity is started. In a sense, onCreate() acts just like a constructor does when an object is created, except it's when an activity is created, and this is done automatically. I did not know that. In the event that your activity is actually an extension of an activity, and contains no onCreate() itself, the super.onCreate() will be called. I am ignoring the two answers that told me to press the run button, and +1 ing the answer that said "Yes". I did not know that onCreate() was a mandatory function that is part of the Activity LifeCycle. – Captainlonate Jul 24 '12 at 06:07
  • just to make some edit in your conclusion, onCreate dont acts as constructor. yes onCreate automatically called when an activity is started, and you can add the code you want to do when activity is being created. – jeet Jul 24 '12 at 06:11
  • When speaking with a colleague, I realized I did not understand that inheritance applied when onCreate() was called by the manifest file on a class that did not explicitly implement onCreate(). I hope this helps someone else. – Captainlonate Jul 26 '12 at 16:55