0

On my fragment I am doing:

    Intent intent = new Intent(getActivity(), OtherActivity.class);

    startActivityForResult(intent, RETURN_CODE);

I have overriden onActivityResult on my Activity

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

    logger.debug("!!ACTIVITY!!!Returned from the activity!!!!");

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

The same goes for the fragment! The problem is that this method is only being called on the Activity and not in the fragment. Any clue why?

apinho
  • 2,235
  • 3
  • 25
  • 39
  • see [this](http://stackoverflow.com/questions/17085729/startactivityforresult-from-a-fragment-and-finishing-child-activity-doesnt-c) question. – mrsus Oct 16 '13 at 09:16

1 Answers1

1

there is an issue with support v4, try using onPostResume in onActivityResult in Activity use following code

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    returningWithResult = true;
    this.mData = data;
    mRequestCode = requestCode;
    mResultCode = resultCode;
}

and in onPostResume

@Override
protected void onPostResume() {
    // TODO Auto-generated method stub
    super.onPostResume();
    if (returningWithResult)
        <your fragment>.actionOnActivityResult(mRequestCode, mResultCode, mData);

    returningWithResult = false;
}

also trying launching intent for result from activity only

public void launchIntent(Intent intent, int code) {
    startActivityForResult(intent, code);
}

In Fragment use

getActivity().launchIntent(intent, PICK_FROM_CAMERA);

I dont know the reason, but it worked for me. Hope it helps.

rachit
  • 1,981
  • 15
  • 23