Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Build a Simple Android App (retired 2014) Shaking Things Up The Activity Lifecycle

Hasan Can Terzi
Hasan Can Terzi
5,892 Points

I couldn't understand what it is asking me?

I couldn't relate with the video

This seems like a fairly vague question. Could you elaborate on what you problem is?

3 Answers

Harry James
Harry James
14,780 Points

Hello,

The answer is this:

    super.onCreate(savedInstanceState);

And I'll explain it now: Q: Inside the 'onCreate()' method of MainActivity, add a line of code to execute the 'onCreate()' method of the parent, or superclass, of this MainActivity class. Don’t forget to pass along the parameter, and call it before the 'aString' variable is set! Explanation: When you declare the superclass, you're saying that you want to do something with that super class (In this case, the super class is Activity, which is what we're extending). So, you're actually writing Activity.onCreate(savedInstanceState) however, you can't actually write this in your code as, Java won't understand what Activity is. Also, the savedInstanceState bit is the same parameter as onCreate() so, you're passing in the same value into the super class's onCreate() method as well. You don't need Bundle at the start as, you've already initialized the variable.

Hope this explains things!

Hasan Can Terzi
Hasan Can Terzi
5,892 Points

Thank you for your answer but I have problem on second problem (2of5) I cant progress now.

Harry James
Harry James
14,780 Points

Ok, the answer here is:

     super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main); 

        aString = "This variable is set AFTER the 'otherString' variable in Activity";

And the reason is because code runs from the top to the bottom. So, when the onCreate() method is called, the first line run is super.onCreate(savedInstanceState). Now, as we know, super is the Activity class so, we're actually running this line of code first (We're running the onCreate method in the super class, Activity) and because the otherString variable is declared here, it will be initialized first. After it has run, it will set the content view and then it will set the value of aString.

So, as super.onCreate() is called first (And otherString will be too), aString will be called AFTER the otherString variable.

Hasan Can Terzi
Hasan Can Terzi
5,892 Points

Thank you for your supports. Aparentemente, I will ask many question :D

Harry James
Harry James
14,780 Points

NP :)

That's what the forums are for :D