Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.app.Application.ActivityLifecycleCallbacks;
import android.content.Context;
import android.os.Bundle;
import android.webkit.CookieManager;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand Down Expand Up @@ -36,6 +37,16 @@ public void onCreate() {
this.registerActivityLifecycleCallbacks(this);
MobileAds.initialize(this, initializationStatus -> {
});
// Pre-warm the WebView system on the main thread. Some ad SDK calls such
// as CookieManager.getInstance() may occur on background threads which
// can cause deadlocks if the WebView provider has not been initialized
// yet. Initializing it here prevents the "AdWorker" threads from
// blocking on WebViewFactory.getProvider.
try {
CookieManager.getInstance();
} catch (Exception ignored) {
// Ignore WebView initialization errors; ads will simply not use cookies.
}
ProcessLifecycleOwner.get().getLifecycle().addObserver(this);
appOpenAdManager = new AppOpenAdManager();
}
Expand Down