Search code examples
javaandroidreturnsuperoncreateoptionsmenu

Why does the Android onCreateOptionsMenu method return super.onCreateOptionsMenu?


As I'm new to Android programming, I've encountered another little thing that I don't understand. Why does the onCreateOptionsMenu method below return super.onCreateOptionsMenu instead of just calling super.onCreateOptionsMenu (as it's done in the onCreate method)?

(This is from an Android tutorial.)

public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu items for use in the action bar
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.main_activity_actions, menu);
    return super.onCreateOptionsMenu(menu);
}

(I've found no duplicate question on StackOverflow. I'm probably asking a silly question or I'm just bad at searching.)


Solution

  • The super.onCreateOptionsMenu(menu): will execute any code that has to be executed for the options menu to work properly. The code you write adds extra functionality/ decides properties of the options menu.