Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

High ANR Rate Caused by WebView Initialization on Main Thread

64 views
Skip to first unread message

Ronald Geisler

unread,
Jan 23, 2025, 3:56:02 AMJan 23
to Google Mobile Ads SDK Developers

Dear AdMob Android SDK Team,

We are currently experiencing a high number of ANRs in our app, which we have traced back to WebView initialization on the main thread. As required by EU regulations, we implement a Consent dialog, but this delays the initialization of AdMob, exacerbating the issue.

We have tried various approaches, including:

  1. Using CoroutineScope.
  2. Adding the following meta-data entry:
    xml
    KopierenBearbeiten
    <meta-data android:name="com.google.android.gms.ads.flag.OPTIMIZE_INITIALIZATION" android:value="true" />

Unfortunately, every combination of these approaches eventually leads to WebView being executed on the main thread, significantly increasing the ANR rate.

The only effective solution we’ve found is to initialize AdMob directly in the onCreate method, create the AdView there, and load an ad. While this approach dramatically reduces ANRs, it significantly increases the app startup time.

Additionally, in some regions, the Consent dialog takes several seconds to display. To address this, we use npa=1 in the initial ad request to minimize delays.

We would like to know:

  1. Is there a way to completely decouple WebView initialization from the main thread?
  2. What best practices can you recommend to reduce the ANR rate without excessively increasing app startup time?

I have attached a screenshot of an app start trace showing the issue for reference.

Thank you for your assistance.

Best regards,

Ronald

WebView.jpg

Mobile Ads SDK Forum Advisor

unread,
Jan 23, 2025, 10:09:19 AMJan 23
to google-adm...@googlegroups.com

Hi Ronald,

Thank you for contacting the Mobile Ads SDK support team.

Initializes the Google Mobile Ads SDK as early as possible after the app launches to reduce latency on the session's first ad request. Please utilize the optimize initialization parameter and also please refer to the Initialize the Google Mobile Ads SDK and call the initialize() method on a background thread within an Activity.
As per this
Register the web view, Call registerWebView() on the main thread to establish a connection with the JavaScript handlers in the AdSense code or Google Publisher Tag within each WebView instance. This should be done as early as possible, such as in the onCreate() method of your MainActivity.

If the issue still persists, share your sample project (not the apk file) where the issue is reproducible.

If the file(s) you are looking to share are less than 25mb in total you can attach them to this case on your next reply. If you are having trouble attaching your file to this case or if your file(s) are larger than 25mb. Kindly follow using the steps below:

1. Navigate to https://docs.google.com/forms/d/e/1FAIpQLSfkAiXMeYP-fw1W3Z-tT9uwmATEKO5X6S-th0gR2ezdKaaqfg/viewform?usp=pp_url&entry.400550049=Mobile+Ads+SDK&entry.460850823=5004Q00002vGy45QAC&entry.80707362=00285592

2. Fill out all fields, and attach your file(s).

3. Please reply back on this thread when you have uploaded your file(s). Please do not share this link.
 
This message is in relation to case "ref:!00D1U01174p.!5004Q02vGy45:ref" (ADR-00285592)

Thanks,
 
Google Logo Mobile Ads SDK Team

Feedback
How was our support today?

rating1    rating2    rating3    rating4    rating5


 


Ronald Geisler

unread,
Jan 27, 2025, 3:05:11 AMJan 27
to Google Mobile Ads SDK Developers

Hi,

I tested the implementation with a dummy WebView, as shown in the attached screenshot. This approach initializes the actual WebView for the banner faster. We plan to include this in the next release for further evaluation.

Best regards,

Ronald


Screenshot 2025-01-27 at 08.59.21.png
Reply all
Reply to author
Forward
0 new messages