File tree Expand file tree Collapse file tree 1 file changed +11
-0
lines changed
app/src/main/java/com/d4rk/androidtutorials/java/ads/managers Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change 55import android .app .Application .ActivityLifecycleCallbacks ;
66import android .content .Context ;
77import android .os .Bundle ;
8+ import android .webkit .CookieManager ;
89
910import androidx .annotation .NonNull ;
1011import androidx .annotation .Nullable ;
@@ -36,6 +37,16 @@ public void onCreate() {
3637 this .registerActivityLifecycleCallbacks (this );
3738 MobileAds .initialize (this , initializationStatus -> {
3839 });
40+ // Pre-warm the WebView system on the main thread. Some ad SDK calls such
41+ // as CookieManager.getInstance() may occur on background threads which
42+ // can cause deadlocks if the WebView provider has not been initialized
43+ // yet. Initializing it here prevents the "AdWorker" threads from
44+ // blocking on WebViewFactory.getProvider.
45+ try {
46+ CookieManager .getInstance ();
47+ } catch (Exception ignored ) {
48+ // Ignore WebView initialization errors; ads will simply not use cookies.
49+ }
3950 ProcessLifecycleOwner .get ().getLifecycle ().addObserver (this );
4051 appOpenAdManager = new AppOpenAdManager ();
4152 }
You can’t perform that action at this time.
0 commit comments