Android Activity states changing #androidapp

+1 Yellow flash · January 11, 2016
so i am writing a simple app that gives toast messages as a response to the activity state change so whenever i am writing the methods oncreate(),onpause,...... these methods giving error to use a "super" keyword and call for "oncreate" method in Activity class(base class) . so my doubt is why is necessary to call base class method in derived class methods like oncreate,onstop.........

protected void onStart(){

Toast.makeText(this,"toast on start",Toast.LENGTH_SHORT).show();
}   can nt i just write like this?

Post a Reply


Oldest  Newest  Rating
0 Gary Whitney · January 11, 2016
I believe the reason is based in the polymorphic nature of Java.

Here is the simple way I think about it.
The default onStart does a lot of housekeeping or has a delegate object that you need.
So you call the super onStart to do the housekeeping and then you add you personal code.

I can't remember how but there are ways to write methods that can't be overridden until you call the super.

If you want to know more, dig into the onStart() in the API and see what it does.
  • 1

Java / Android Development


Very popular language used to create desktop applications, website applets, and Android apps.

Bucky Roberts Administrator