Skip to content

Fix LocaleUtils creating WebView in the background → ANR#87

Draft
Copilot wants to merge 6 commits intomasterfrom
copilot/fix-localeutils-background-webview-anr
Draft

Fix LocaleUtils creating WebView in the background → ANR#87
Copilot wants to merge 6 commits intomasterfrom
copilot/fix-localeutils-background-webview-anr

Conversation

Copy link
Contributor

Copilot AI commented Jan 13, 2026

Fix LocaleUtils creating WebView in the background → ANR

Changes Completed:

  • Understand the issue: WebView creation in Application.onCreate() causing ANR
  • Research: Confirmed WebView creation must be done on UI thread (Android requirement)
  • Remove LocaleUtils.onApplicationCreate(this) call from MTApplication.onCreate()
  • Add LocaleUtils.fixWebViewLocale(this) call to SplashScreenActivity.onCreate() to run it once in the foreground
  • Verify the changes compile and don't break existing functionality
  • Code review completed
  • Security check completed (no issues found)

Summary:

This PR fixes an ANR issue by moving the WebView locale initialization from MTApplication.onCreate() (which can run in the background) to SplashScreenActivity.onCreate() (which always runs on the UI thread in the foreground).

Files Changed:

  1. MTApplication.kt (line 62 removed): Removed LocaleUtils.onApplicationCreate(this) call
  2. SplashScreenActivity.kt (line 11 & 40): Added LocaleUtils import and call to fixWebViewLocale(this)

Why This Works:

  • WebView must be created on the main/UI thread (Android requirement)
  • Application.onCreate() can run in the background during app initialization
  • SplashScreenActivity is the first user-visible Activity, guaranteeing foreground execution on the UI thread
  • The WebView initialization now happens once, on the correct thread, preventing ANR errors
  • Using fixWebViewLocale() directly provides clearer intent than the wrapper method onApplicationCreate()

Security Check:

✅ No security vulnerabilities detected

Original prompt

This section details on the original issue you should resolve

<issue_title>Fix LocaleUtils creating WebView in the background -> ANR</issue_title>
<issue_description>- https://github.com/mtransitapps/mtransit-for-android/blob/master/app-android/src/main/java/org/mtransit/android/ui/MTApplication.kt

Should move it to SplashScreenActivity so it's only done once, in the foreground.

Crashlytics:
https://console.firebase.google.com/project/montransitapps/crashlytics/app/android:org.mtransit.android/issues/db4a097fb036bfda7ebfbaaa7573338e

       at android.webkit.WebView.<init>(WebView.java:322)
       at org.mtransit.android.commons.LocaleUtils.onApplicationCreate(LocaleUtils.java:46)
       at org.mtransit.android.ui.MTApplication.onCreate(MTApplication.kt:62)
       at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1213)
```</issue_description>

<agent_instructions>Should only make changes in `SplashScreenActivity.kt` and `MTApplication.kt`

Check if it's possible to call `new WebView(context).destroy()` in background thread</agent_instructions>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…enActivity to fix ANR

Co-authored-by: mmathieum <177998+mmathieum@users.noreply.github.com>
Copy link
Member

@mmathieum mmathieum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot please use the new LocaleUtils``fixWebViewLocale function directly in Splashscreen

…reate()

Co-authored-by: mmathieum <177998+mmathieum@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 10, 2026

@copilot please use the new LocaleUtils``fixWebViewLocale function directly in Splashscreen

Done. Changed to call LocaleUtils.fixWebViewLocale(this) directly in commit ea36e6b.

Copilot AI changed the title [WIP] Fix LocaleUtils creating WebView in the background Fix LocaleUtils creating WebView in the background → ANR Feb 10, 2026
Copilot AI requested a review from mmathieum February 10, 2026 19:24
@mmathieum
Copy link
Member

Done with FF here:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix LocaleUtils creating WebView in the background -> ANR

2 participants