Calling the updateQuestion method?


#1

Can someone explain how this code is working, please? :sunglasses:

On page 42, a call to updateQuestion() is made after the onCreate(Bundle savedInstanceState) is called. I thought non-static methods like updateQuestion() couldn’t be called without an object.

How is it possible that the code works as is without the method being static and not being called by an object?


#2

Ok, I’ve been looking at the code for a bit with a fresh mind. I’m starting to think that when onCreate() is called, the method creates an object of QuizActivity. The method updateQuestion() is then called by this instance object therefore the method isn’t static.

The code shows:

onCreate(Bundle savedInstanceState){
super.onCreate(…)

updateQuestion();

}

Above updateQuestion() is just another way of writing this.updateQuestion(); ? Am I correct in thinking this? Thanks!


#3

The Android framework creates your activity instance for you. So onCreate is being called on your newly-created instance, on which you can safely call all the methods you like.


#4

Ahh ok. Thanks for the explanation. It really helped!