Hello! I am learning little by little development on Android. Create a menu! It seems to work! I create in a method

public boolean onCreateOptionsMenu(Menu menu). 

I create through add. I return the menu

 retyrn super.onCreateOptionsMenu(menu); 

So here is the question. What is super.onCreateOptionsMenu(menu) ? I would like to understand logically, rather than stupidly writing code.

Thank you all!

  • I will give advice - read first the book "java 7 the complete reference". At least the first part (300 pages). Posted by Herbert Shieldt In Russian, the book is called "Java 7 Complete Guide." The fact is that you teach Java inconsistently - without knowing the basics, you climb into the android. - arg
  • @argamidon, yes, this is not only about Java. It's better to read books on OOP here) - Suvitruf
  • @argamidon, Ok I will read 300 pages) I just really want to learn how to work on android. On OOP basically it is familiar, kodil for PHP. Therefore, the principle understand that, how and where. I understand that yes, the function returns the menu. Just do not understand why super. What kind of superclass is this?))) - duddeniska
  • The word super is a pointer to the class from which you inherited. Those. which class you wrote from extends - the base version of the method of the inherited class is called. In that book, this is told very sensibly and intelligibly. - arg

1 answer 1

 super.onCreateOptionsMenu(menu); 

This is a call to the base class method so that the correct menu initialization is.

This also applies to other methods: onResume (), onStop (), etc.

  • Why it is impossible to simply write return onCreateOptionsMenu (menu), and necessarily super.? - duddeniska
  • @duddeniska, because then the base class method, where there is code for initializing the menu, will not be called. - Suvitruf
  • @falstaf, what if something serious was done there? I spoke about redefinition of methods as a whole, and not just about a specific example. - Suvitruf
  • @falstaf, btw, for Activity: public boolean onCreateOptionsMenu (Menu menu) {if (mParent! = null) {return mParent.onCreateOptionsMenu (menu); } return true; } - Suvitruf