Often I meet the code, something like this:

@Override public boolean onOptionsItemSelected(MenuItem menuItem){ super.onOptionsItemSelected(menuItem); switch (menuItem.getItemId()){ case R.id.add: Toast.makeText(getContext(), "Add", Toast.LENGTH_SHORT).show(); } return true; } 

And all of them have the string super.onOptionsItemSelected(menuItem); . As I understand it, the superclass method is called, but why? Removed this line, everything works.

  • works if the entire super chain consists of empty methods, or you don’t notice something - Igor

1 answer 1

This is done so that if there is already an implementation of this method in the superclass, she volunteered and did everything she needed. Specifically, in this case, the method of the superclass apparently does not do anything, so the program behavior does not change.