我正在使用 Wootrick SDK 创建一个桥梁来响应 native 。当我调用特定函数时,我会收到以下日志,但 Wootric Survey 不会显示。
java.lang.IllegalStateException: Method addObserver must be called on the main thread
我的代码如下,
@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());
}
}
有人可以帮我解决上述问题吗?
最佳答案
您可以在主线程上执行 Wootric 初始化代码,如下所示:
currentActivity.runOnUiThread(new Runnable() {
@Override
public void run() {
// initialize Wootric here
}
});
关于android - React Native Android 桥错误 : Method addObserver must be called on the main thread,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70589874/