gpt4 book ai didi

android - onActivityResult 未在 fragment 中调用

转载 作者:行者123 更新时间:2023-11-29 16:54:17 25 4
gpt4 key购买 nike

fragment 中的代码

 private static final int BRAINTREE_REQUEST_CODE = 777;
BottomMenu fragment = this;
public void onBraintreeSubmit(String clienTtoken) {
DropInRequest dropInRequest = new DropInRequest().clientToken(clienTtoken);
startActivityForResult(dropInRequest.getIntent(getActivity()), BRAINTREE_REQUEST_CODE);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {

if (requestCode == BRAINTREE_REQUEST_CODE) {
if (resultCode == Activity.RESULT_OK) {
DropInResult result = data.getParcelableExtra(DropInResult.EXTRA_DROP_IN_RESULT);
Toast.makeText(getActivity(), result.getPaymentMethodNonce().getNonce() + "", Toast.LENGTH_SHORT).show();
// use the result to update your UI and send the payment method nonce to your server
sendPaymentNonceToServer(result.getPaymentMethodNonce().getNonce());
} else if (resultCode == Activity.RESULT_CANCELED) {
// the user canceled
} else {
// handle errors here, an exception may be available in
Exception error = (Exception) data.getSerializableExtra(DropInActivity.EXTRA_ERROR);
}
}
}

Activity 代码

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

问题:

I have implemented BrainTree payment gateway with onBraintreeSubmit() method I startActivityResult and catch it onActivityResult but it's not being called in the fragment.

onActivityResult only gets called if I cancel payment but never when payment success or exception thrown

最佳答案

First you have to call from activity Add below code in your activity

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

Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.frameLayout);
fragment.onActivityResult(requestCode, resultCode, data);

}

关于android - onActivityResult 未在 fragment 中调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45431100/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com