0

I know there is so many question related to this but I still not find any solution i have tried all the things.

from onActivityResult() not called when Activity started from Fragment I find

      getActivity().startActivityForResult(galleryIntent, PICK_IMAGE);

with

      startActivityForResult(galleryIntent, PICK_IMAGE);

onActivityResult is not being called in Fragment

     super.onActivityResult //on activity

I have also done this but still it's not working.

does any body has solution?

thanks

Community
  • 1
  • 1
Siddhpura Amit
  • 14,534
  • 16
  • 91
  • 150

3 Answers3

0

If you are using getActivity().startActivityForResult(galleryIntent, PICK_IMAGE); then you have to call onActivityResult() in your activity class where you are adding your fragment.

And If you are using startActivityForResult(galleryIntent, PICK_IMAGE); inside the fragment then you have to call onActivityResult() in your fragment class.

Pr38y
  • 1,565
  • 13
  • 21
0

In the Activity you're creating set the result using an intent. onActivityResult() will catch the intent for you to process. Here's an example of returning an int value.

public void sendResultToFragment(int result) {
    Intent resultIntent = new Intent();

    resultIntent.putExtra("int-result", result);
    setResult(Activity.RESULT_OK, resultIntent);
}

Keep the super.onActivityResult(...) override in your main activity where your fragment lives.

You must override onActivityResult() in your Fragment

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

    switch(requestCode) {
    case PICK_IMAGE:
        int result = data.getInt("int-result");

        // Do stuff

        break;
    default:
        super.onActivityResult(requestCode, resultCode, data);
    }
}
RoraΖ
  • 634
  • 9
  • 21
0

Hi i had the same problem and i realized that i opened the activity with the flag FLAG_ACTIVITY_NO_HISTORY

new Intent(SplashActivity.this, StartedActivity.class).setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY)

The documentation mentions that when the noHistory attribute is set to true or the flag in the intent, then finish() is called on the Activity when the user navigates away from the Activity.

So just remove and the problem will be solved.

Btw i have the onActivityResult just in the fragment, it works great for me hope it helps.

The answer i found it here

Community
  • 1
  • 1
Kokusho
  • 1,113
  • 1
  • 9
  • 14