Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

android

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()     ... } 
like image 780
Prizoff Avatar asked Jul 31 '12 17:07

Prizoff


People also ask

What is super onActivityResult?

In short super(). onActivityResult() is use to handle the error or exception during execution of Intent.

What is the use of onActivityResult in Android?

When you done with the subsequent activity and returns, the system calls your activity's onActivityResult() method. This method includes three arguments: @The request code you passed to startActivityForResult() . @A result code specified by the second activity.


1 Answers

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.

like image 142
hcarver Avatar answered Oct 05 '22 23:10

hcarver