braintree_android: Google Pay crash when using 4.10.0 in some cases
General information
- SDK/Library version: 4.10.0
- Environment: Production
- Android Version and Device: Many devices, such as Galaxy A12 with Android 11
Issue description
When we are going to launch Google pay in version 4.10.0. It will crash sometimes.
Caused by java.lang.NullPointerException: Attempt to invoke virtual method 'void androidx.activity.result.ActivityResultLauncher.launch(java.lang.Object)' on a null object reference
at com.braintreepayments.api.GooglePayLifecycleObserver.launch(GooglePayLifecycleObserver.java:44)
at com.braintreepayments.api.GooglePayClient$4$1.onResult(GooglePayClient.java:296)
at com.braintreepayments.api.ConfigurationLoader.loadConfiguration(ConfigurationLoader.java:41)
at com.braintreepayments.api.BraintreeClient$1.onAuthorizationResult(BraintreeClient.java:161)
at com.braintreepayments.api.AuthorizationLoader.loadAuthorization(AuthorizationLoader.java:20)
at com.braintreepayments.api.BraintreeClient.getAuthorization(BraintreeClient.java:170)
at com.braintreepayments.api.BraintreeClient.getConfiguration(BraintreeClient.java:157)
at com.braintreepayments.api.GooglePayClient$4.onAuthorizationResult(GooglePayClient.java:275)
at com.braintreepayments.api.AuthorizationLoader.loadAuthorization(AuthorizationLoader.java:20)
at com.braintreepayments.api.BraintreeClient.getAuthorization(BraintreeClient.java:170)
at com.braintreepayments.api.GooglePayClient.requestPayment(GooglePayClient.java:271)
at com.braintreepayments.api.GooglePayClient.requestPayment(GooglePayClient.java:228)
.....
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 19 (9 by maintainers)
@contissi it may be specific to Google Pay here. The workaround could be removed if
tokenizewere called in response to a user action e.g. a “Google Pay” button press, only because the host activity will presumably be in aRESUMEDstate.We use Jetpack Lifecycle internally to register for an activity result in
onCreate. TheHandlerworkaround is a bit of a hack to get the code to execute on the next run loop, which will be executed after all of the pending lifecycle methods i.e.onCreate,onResumeetc. have completed synchronously.For now it is a good workaround. In the future, we should offer explicit support for
onCreatetokenization by capturing a pendingGooglePayRequestinternally which will allow the SDK to defer launching the Google Pay flow until after Activity result registration is complete.