Open AG-Akash09 opened 6 months ago
Hey @AG-Akash09, thanks for the message. We’re aware of limitations with the current constructor and would need to make a breaking change to truly resolve this issue. We may investigate this further and publish a long term fix as part of a beta release of our next major version but this is not on our current roadmap.
In the meantime, the following workaround strategy may work:
val clientTokenProvider = ClientTokenProvider { callback ->
viewModel.paymentToken.observe(viewLifecycleOwner, {
callback.onSuccess(it)
}
}
dropInClient = DropInClient(fragmentActivity, clientTokenProvider)
Thanks for your active response. I have tried the workaround strategy, but still the same issue is encountered, i.e.
"java.lang.IllegalStateException: LifecycleOwner com.andateknoloji.apps.nybox.MainActivity@d5a363d is attempting to register while current state is RESUMED. LifecycleOwners must call register before they are STARTED.
at androidx.activity.result.ActivityResultRegistry.register(ActivityResultRegistry.java:123)
at com.braintreepayments.api.DropInLifecycleObserver.onCreate(DropInLifecycleObserver.java:30)
at androidx.lifecycle.FullLifecycleObserverAdapter.onStateChanged(FullLifecycleObserverAdapter.java:36)
at androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.java:360)
at androidx.lifecycle.LifecycleRegistry.addObserver(LifecycleRegistry.java:202)
at com.braintreepayments.api.DropInClient.addObserver(DropInClient.java:187)
at com.braintreepayments.api.DropInClient.
@AG-Akash09 can you try removing the outer viewModel.paymentToken.observe(viewLifecycleOwner,
Braintree SDK Version
6.15.0
Environment
Both
Android Version & Device
No response
Braintree dependencies
Describe the bug
Our network calls are seamlessly integrated with coroutines and view models. To retrieve the client token from our server, we employ a suspend function and observe its value in the onCreateView function. However, attempting to pass the client token to DropInClient results in a crash, accompanied by the error 'java.lang.IllegalStateException: LifecycleOwner MembershipFragment is attempting to register while current state is RESUMED. LifecycleOwners must call register before they are STARTED.' Although registering directly with the DropInClient within onCreateView using the tokenization key works flawlessly, we're constrained by the tokenization key's limitations, necessitating our reliance on the client token exclusively.
To reproduce
Code Snippet viewModel.paymentToken.observe(viewLifecycleOwner, Observer { Log.d("Payment Token ","$it") val fragmentActivity = requireActivity(); dropInClient = DropInClient(fragmentActivity,it) val dropInRequest = DropInRequest()
Expected behavior
DropInClient should registered successfully
Screenshots