Skip to content

MainActivity: catch ActivityNotFoundException in WebView URL handoff#15

Open
jim-daf wants to merge 1 commit into
rnauber:masterfrom
jim-daf:fix-webview-anf-crash
Open

MainActivity: catch ActivityNotFoundException in WebView URL handoff#15
jim-daf wants to merge 1 commit into
rnauber:masterfrom
jim-daf:fix-webview-anf-crash

Conversation

@jim-daf
Copy link
Copy Markdown

@jim-daf jim-daf commented May 20, 2026

Closes #14.

Summary

MyWebViewClient.shouldOverrideUrlLoading calls startActivity(Intent.ACTION_VIEW, uri) with no try / catch. On a device that has no handler for the URI scheme, that throws ActivityNotFoundException and crashes the Activity mid-game. This PR wraps the launch and falls back to a Toast.

Changes

  • MainActivity.java -- import ActivityNotFoundException and Toast; wrap the startActivity call in try / catch; log the failure and show No app to open this link.

Test plan

  • Tap an http(s) link the game might surface on a device with a browser -- browser opens, game pauses as before.
  • Tap an http(s) link on an emulator with com.android.chrome disabled -- Toast appears, game keeps running.

MyWebViewClient.shouldOverrideUrlLoading forwards every URL the
embedded HTML page navigates to with a plain startActivity(Intent.
ACTION_VIEW). If the device has no installed app that handles the
URI (a tablet without a browser, a stripped GSI build, a tel: link
on a non-phone form factor, ...), startActivity throws
ActivityNotFoundException and the Activity is torn down mid-game.

Wrap the launch in try / catch and surface a Toast so a missing
handler scopes the failure to that single click instead of crashing
the whole Activity.
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.

MainActivity WebView can crash on links no installed app can open

1 participant