我有一个bottomNavigationActivity和一些片段(例如homeFragment,settingsFragment)。
在homeFragment中,我有一个回收站视图。选中一行后,它将请求客户令牌,并显示一个braintree dropin UI,
在homeRecyclerAdapter中:
view.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
...
clientToken = response.body().getClientToken();
DropInRequest dropInRequest = new DropInRequest()
.clientToken(clientToken);
// Display Drop in
Context context = view.getContext();
Intent intent = dropInRequest.getIntent(context);
context.startActivity(intent);
}
它能够显示脑力下降的信息,但是,一旦解散或选择了付款方式,我如何获得该事件?
如果我正在使用活动来显示此下拉列表而不是使用回收站适配器,则设法获取了该事件,这可以通过使用“ startActivityForResult(dropInRequest.getIntent(getBaseContext( )),10)”和 “ onActivityResult”:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 10) {
if (resultCode == Activity.RESULT_OK) {
DropInResult result = data.getParcelableExtra(DropInResult.EXTRA_DROP_IN_RESULT);
// use the result to update your UI and send the payment method nonce to your server
// Run postNonceToServer code
Log.d(TAG, "RESULT_OK");
} else if (resultCode == Activity.RESULT_CANCELED) {
// the user canceled
Log.d(TAG, "RESULT_CANCELED");
} else {
// handle errors here, an exception may be available in
Exception error = (Exception) data.getSerializableExtra(DropInActivity.EXTRA_ERROR);
Log.d(TAG, "EXTRA_ERROR");
}
}
}