Reputation: 91
I have this code
Intent intent = new Intent(getActivity(), PaymentActivity.class);
intent.putExtra(PaymentActivity.EXTRA_PAYMENT, thingToBuy);
getActivity().startActivityForResult(intent, paypal.REQUEST_CODE_PAYMENT);
override function call onActivityResult but it call the result.
Upvotes: 0
Views: 577
Reputation: 970
Where do you override the onActivityForResult method?.
If the answer is in your FragmentActivity. You should use: getActivity().startActivityForResult
If the answer is in your Fragment. You should use: startActivityForResult.
Upvotes: 0
Reputation: 11517
If you call startActivityForResult
from the Fragment
the result will deliver to the Fragment
. And if you call startActivityForResult
from the Activity
the result will deliver to the Activity
. When Fragment
calls StartActivityForResult
the requestCode
will be changed by the Activity
, so it will know how to deliver the result to which Fragment
.
In your case you should change line:
getActivity().startActivityForResult(intent, paypal.REQUEST_CODE_PAYMENT);
to:
startActivityForResult(intent, paypal.REQUEST_CODE_PAYMENT);
Upvotes: 1
Reputation: 1289
Do not use getActivity().startActivityForResult(intent, paypal.REQUEST_CODE_PAYMENT);
This calls onActivityResult in the activity
Instead use the method in fragment
startActivityForResult(intent, paypal.REQUEST_CODE_PAYMENT);
Upvotes: 1