0

I'm trying to pass and receive data between two applications, AppA and AppB. In my AppA, I have an AppAActivity.java that has AppAFragment within. I want this fragment to open AppB which has an AppBActivity.java that opens Login fragment, then Payment fragment then Acknowledgement fragment. This Acknowledgement fragment has a "Next" button which upon click, will call the setResult method so that it will now alert the AppAFragment to receive the result. But the onActivityResult method from the AppAFragment responsible for receiving the result, is not being called again.

AppAFragment.java

@Override
public void openUrl() {
    Intent intent = getBaseParentActivity().getPackageManager()
            .getLaunchIntentForPackage(DataConstants.SAMPLE_RIB_PACKAGE);
    intent.setAction(Intent.ACTION_SEND);
    intent.putExtra(DataConstants.TRANSACTION_REFERENCE, getLinkWS()
            .getTransRef());
    intent.putExtra(DataConstants.TRANSACTION_AMOUNT, mAmount.getText()
            .toString());
    intent.setType(MediaType.TEXT_PLAIN);
    startActivityForResult(intent,
            DataConstants.CODE_APP_TO_APP_PAYMENT);
}

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

    if (resultCode == Activity.RESULT_OK
            && requestCode == DataConstants.CODE_APP_TO_APP_PAYMENT) {

        Log.v("Test", "Test");

        Toast.makeText(getBaseParentActivity(),
                data.getStringExtra(DataConstants.BANK_REFERENCE_NO),
                Toast.LENGTH_SHORT).show();         
    }
}

AcknowledgementFragment.java

@Override
public void buttonNext() {
    Intent intent = new Intent();
    intent.putExtra(DataConstants.BANK_REFERENCE_NO, infoModel.getBankRef());

    getActivity().setResult(Activity.RESULT_OK, intent);
    getActivity().finish();
}

Thank you very much!

Rain
  • 11
  • 2
  • try moving `onActivtyResult` from **AppAFragment** to **AppAActivity**. In Android, Activities are the main flow of communication of intents. An intent can launch an Activity which then launches the fragment, so for best coding performances, any intent stuff should be sent and received by Activities – dsrees Jan 14 '15 at 03:48

1 Answers1

0

This might be a Possible cause for the behavior. Kindly check.

Since your fragment is part of activity AppAFragment, even though fragment is the one making the startActivityForResult call, the activity gets the first shot at handling the result.

To get the result in your fragment try :

startActivityForResult(intent,111);

instead of

getActivity().startActivityForResult(intent,111); inside your fragment.

Also, In your activity onActivityResult method, try adding this line

super.onActivityResult();
Prem
  • 4,823
  • 4
  • 31
  • 63