Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Android Build an Interactive Story App (Retired) Intents and Multiple Activities Adding a Second Activity

Keivan Norouzi
Keivan Norouzi
4,513 Points

Why don't we need "super" keyword before startActivity method in our startStory method?

I wonder how the program still works, we use the method startActivity that belongs to the super(parent class) which in this case is Activity class, without writing "super" keyword before it !?!

1 Answer

Ben Deitch
STAFF
Ben Deitch
Treehouse Teacher

We don't need the super keyword before startActivity because MainActivity IS an Activity. When we override a function the underlying function is entirely replaced. That's why we call super so frequently in Android; we want to call the parent's method as well as the child's. Here's an example:

public class Cake {
    public void onCreate() {
        mixIngredients();
        putInPan();
        bakeACake();
    }

    public void notifyCakeFinished() {
        callClient();
    }
}

public class WeddingCake extends Cake {
    @Override
    public void onCreate() {
        super.onCreate();
        decorateCake();
        notifyCakeFinished();
    }
}
Keivan Norouzi
Keivan Norouzi
4,513 Points

Thank you so much, it helped me a lot to understand it. :)