Question

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

    super.onActivityResult(requestCode,resultCode,data)

    if (requestCode == Selectedimage && resultCode == RESULT_OK && data != null) {

        Uri pickedImage = data.getData();
        Intent send= new Intent(Selection.this,Imagepage.class);
        send.putExtra("pickedImage",pickedImage.toString());
        startActivity(send);
    }
}

what is the use of adding that super.onActivityResult line ? and also when am adding that, its showing some error.

Was it helpful?

Solution 2

First of all, if you get an error - always show logcat. Secondly, if this method is declared in the class extending Activity, there is no need to call super there since this method is empty in the Activity class:

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

OTHER TIPS

The onActivityResult() is a little like onOptionMenuSelected(), in the way that:

  1. Based on the params, you can tell if this function call should be processed in this level
  2. if so, process with it and return (true)
  3. if not, just call the super class's implementation

Therefore, in your Fragment's onActivityResult(), you should first check if the requestCode meets what you set before, if so, deal with the data and return. If not, just return with super.onActivityResult().

A simple sample may look like:

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
    case SELECT_FILE_TO_UPLOAD:
        // upload a file
        return;

    case SELECT_FILE_TO_DELETE:
        // delete a file
        return;

    default:
        super.onActivityResult(requestCode, resultCode, data);
    }
}

The call does not really do anything (link to source code) so you can omit it if it's giving problems.

The fact that it does is weird considering the empty super implementation though.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top