1

I am getting the following error:

Fatal Exception: java.lang.RuntimeException
java.lang.Throwable: A WebView method was called on thread 'mqt_native_modules'. All WebView methods must be called on the same thread. (Expected Looper Looper (main, tid 2) {7e18f70} called on Looper (mqt_native_modules, tid 513) {4860cd5}, FYI main Looper is Looper (main, tid 2) {7e18f70})
Fatal Exception: java.lang.RuntimeException: java.lang.Throwable: A WebView method was called on thread 'mqt_native_modules'. All WebView methods must be called on the same thread. (Expected Looper Looper (main, tid 2) {7e18f70} called on Looper (mqt_native_modules, tid 513) {4860cd5}, FYI main Looper is Looper (main, tid 2) {7e18f70})
       at android.webkit.WebView.checkThread(WebView.java:2615)
       at android.webkit.WebView.loadUrl(WebView.java:742)
       at com.iab.omid.library.appnexus.b.e.a(:30)
       at com.iab.omid.library.appnexus.b.e.a(:30)
       at com.iab.omid.library.appnexus.b.e.a(:12)
       at com.iab.omid.library.appnexus.publisher.AdSessionStatePublisher.a(:8)
       at com.iab.omid.library.appnexus.b.f.a(:30)
       at com.iab.omid.library.appnexus.a.d.d(:4)
       at com.iab.omid.library.appnexus.a.d.onChange(:15)
       at android.database.ContentObserver.onChange(ContentObserver.java:153)
       at android.database.ContentObserver.onChange(ContentObserver.java:169)
       at android.database.ContentObserver.onChange(ContentObserver.java:187)
       at android.database.ContentObserver.onChange(ContentObserver.java:202)
       at android.database.ContentObserver.lambda$dispatchChange$0$ContentObserver(ContentObserver.java:282)
       at android.database.ContentObserver$$ExternalSyntheticLambda0.run(:10)
       at android.os.Handler.handleCallback(Handler.java:938)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loopOnce(Looper.java:226)
       at android.os.Looper.loop(Looper.java:313)
       at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:226)
       at java.lang.Thread.run(Thread.java:920)

I have built a React Native application that fetches ads through this library which I have connected though a Native Module. The ads are fetched on app start and this is the native code I use to fetch the ads:

errors = Arguments.createMap();
loadedPlacementIds = Arguments.createArray();
numAdsRequested = placementIds.size();

adRequests = new ArrayList<>();
for (int i = 0; i < numAdsRequested; i++) {
    String placementId = placementIds.getString(i);
    NativeAdRequest adRequest = new NativeAdRequest(context, placementId);
    NativeAdRequestListener nativeAdRequestListener = new NativeAdRequestListener() {
        @Override
        public void onAdFailed(ResultCode resultCode, ANAdResponseInfo anAdResponseInfo) {
            errors.putString(placementId, resultCode.getMessage());
        }

        @Override
        public void onAdLoaded(NativeAdResponse response) {
            ((MainApplication) context.getCurrentActivity().getApplication()).setAdResponse(response, placementId);
            loadedPlacementIds.pushString(placementId);
        }
    };
    adRequest.setListener(nativeAdRequestListener);
    adRequest.setClickThroughAction(ANClickThroughAction.RETURN_URL);
    adRequests.add(adRequest);
}

MultiAdRequestListener multiAdRequestListener = new
        MultiAdRequestListener() {
            @Override
            public void onMultiAdRequestCompleted() {
            }

            @Override
            public void onMultiAdRequestFailed(ResultCode code) {
                WritableMap params = Arguments.createMap();
                params.putString("error", code.getMessage());
                sendEvent(context, "multiAdRequestDidFail", params);
            }
        };
multiAdReq = new ANMultiAdRequest(context, 12345, multiAdRequestListener);
for (NativeAdRequest adRequest : adRequests) {
    multiAdReq.addAdUnit(adRequest);
}
multiAdReq.load();

The crash seems to happen only when the app is backgrounded and not immediately once it's backgrounded but a few minutes after according to my crash logs: enter image description here

Does anyone have any suggestions of what the issue could be? I have gone though the library and can't really find any uses of WebView in the methods I am using to load the ads.

Daniel Tovesson
  • 2,550
  • 1
  • 30
  • 41

0 Answers0