Home > Software engineering >  React Native Android Bridge Error: Method addObserver must be called on the main thread
React Native Android Bridge Error: Method addObserver must be called on the main thread

Time:01-05

I am using Wootrick SDK for create a bridge to react native. When I'm calling a specific function I'm getting following log and Wootric Survey doesn't show.

java.lang.IllegalStateException: Method addObserver must be called on the main thread

My code as follows,

@ReactMethod
public void configureWithClientID(String clientId, String accountToken) {
Activity currentActivity = getCurrentActivity();

if (currentActivity == null) {
  Log.e("WOOTRIC", "Current activity is null");
  return;
}

try {
  wootric = Wootric.init(currentActivity, clientId, accountToken);
} catch (Exception e) {
  Log.e("WOOTRIC", e.toString());
}

}

Can someone help me to solve the above issue.

CodePudding user response:

You can execute the Wootric initialization code on the main thread with something like this:

currentActivity.runOnUiThread(new Runnable() {
    @Override
    public void run() {
        // initialize Wootric here
    }
});
  •  Tags:  
  • Related