Is there a need to use super.onActivityResult() in onActivityResult()?

Which one is better and why?

This one:

@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);

    ...
}

or this:

@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    // do not call super.onActivityResult()
    ...
}

The first one is better.

It's more consistent with other event functions in the Activity API, it costs you nothing (the code you're calling does nothing at the moment), and it means you don't need to remember to add the call in the future when the behaviour of the base class changes.

Edit

As Su-Au Hwang has pointed out, my prediction about the behaviour of the base class changing in the future has come true! FragmentActivity requires you to call the method on super.


You should call super.onActivityResult if you are using FragmentActivity from the support package (also SherlockFragmentActivity). Otherwise it isn't necessary, however i'd just plug it in there for the sake of it. Check the source of FragmentActivity (no onActivityResult is not empty).

FragmentActivity source


Unless you have multiple subclasses of Activity which depend on it in your application, it doesn't look like calling super.onActivityResult() is needed, since the implementation of onActivityResult() is empty (I checked API level 15).


You can answer this yourself by looking at the source code for Activity.

Basically it's implementation of onActivityResult(...) looks like this...

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
}

...so does nothing.