This is an example app to demo a problem with nested fragments and wallet
https://github.com/zumper/WalletTest
Here is the structure of the app in terms of nesting
MainActivity
|
+-> TopLevelFragment
|
+-> NestedFragment
|
+-> SupportWalletFragment
The SupportWalletFragment
is configured with a request code of 3333
via
public static final int WALLET_REQUEST_CODE = 3333;
...
WalletFragmentInitParams.Builder startParamsBuilder =
WalletFragmentInitParams.newBuilder()
.setMaskedWalletRequest(generateMaskedWalletRequest("10.99"))
.setMaskedWalletRequestCode(WALLET_REQUEST_CODE);
But when the payment method is selected from the wallet activity the result is delivered via
MainActivity.onActivityResult()
with a request code value of 66036
and then to TopLevelFragment.onActivityResult()
with a request code value of 500
.
That's it. NestedFragment.onActivityResult()
is never called with the expected request code of 3333
This problem seems to be a known issue:
http://blog.shamanland.com/2014/01/nested-fragments-for-result.html
https://code.google.com/p/android/issues/detail?id=40537
I can work around the problem in our real code by intercepting the onActivityResult()
and relaying the params via event bus or something.
The tricky part is the fact that I don't even get the correct requestCode
passed in... This makes all my hacks very brittle.
We have a fragment heavy application and I am unable to reduce the hierarchy more than I already have.
Are there other options for addressing this?