question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

6.5.0 DropInClient - Method addObserver must be called on the main thread

See original GitHub issue

I am working on react native module for DropIn and getting this error on initialization of DropInClient

implementation "com.braintreepayments.api:drop-in:6.5.0

         val dropInClient = DropInClient(currentActivity as AppCompatActivity?,clientToken)
         

Method addObserver must be called on the main thread

Why this error can appear?

Issue Analytics

  • State:open
  • Created 9 months ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
molchanovskiycommented, Dec 12, 2022

@wayson I found a solution. You can init the drop in client with an empty token in onCreate() of Activity with shared instance and then use it inside the module by providing token and calling invalidateClientToken which will trigger fetch client token callback.

Activity onCreate():

      val dropInClient = DropInClient(this, ClientTokenProvider { callback ->
            // fetch client token asynchronously...
            callback.onSuccess(BraintreeSharedInstance.instance.clientToken);
        })
        BraintreeSharedInstance.instance.dropInClient = dropInClient
    Module call:
        BraintreeSharedInstance.instance.clientToken = token
          val dropInClient:DropInClient? = BraintreeSharedInstance.instance.dropInClient
          dropInClient?.invalidateClientToken()
          dropInClient?.setListener(PaymentDropInListener())
          dropInClient?.launchDropIn(dropInRequest)
        
0reactions
waysoncommented, Dec 11, 2022

@sshropshire Thanks for your reply. I’ve tried that but DropInClient can only be called in onCreate() on Activity. Otherwise we will have error of Method addObserver must be called on the main thread.

I’ve also tried

currentActivity.runOnUiThread(new Runnable() {
    @Override
    public void run() {
        // initialize DropInClient here
    }
});

But the app just crash straight away after this call.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Android Navigation Instrumentation test throws Method ...
IllegalStateException : Method addObserver must be called on the main thread. My environment: fragment_version = 1.2.5 nav_version = 2.3.1 ...
Read more >
Method addObserver must be called on the main thread #772
Hello, I have an issue when trying to import dji sdk to android app. Registering app crashes the app because of this error...
Read more >
IllegalStateException: Method addObserver must be called on ...
I've updated two dependencies in my project: ... and now I see that NavController::navigate needs to be called from the main thread. Otherwise...
Read more >
[Android] Method addObserver must be called on the main ...
Got this error while trying to setup Purchases 3.4.3 in React Native. Method addObserver must be called on the main thread. Anyone faced...
Read more >
Android SDK init on main thread
has to be called on main thread or it will throw: java.lang.IllegalStateException: Method addObserver must be called on the main thread
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found