Skip to content

fix(webview): guard external-link launches with try/catch#76

Open
jim-daf wants to merge 1 commit into
AndroidLabs-org:mainfrom
jim-daf:fix-webview-startactivity
Open

fix(webview): guard external-link launches with try/catch#76
jim-daf wants to merge 1 commit into
AndroidLabs-org:mainfrom
jim-daf:fix-webview-startactivity

Conversation

@jim-daf
Copy link
Copy Markdown

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

Closes #75.

DocsViewerActivity and BackupWebView both route tapped links to the system browser with raw context.startActivity(intent) calls inside shouldOverrideUrlLoading. If nothing on the device handles the link (no browser, custom scheme, etc.) the call raises ActivityNotFoundException and the host crashes mid-tap. In BackupWebView the call sits inside a Dispatchers.IO coroutine, so the failure brings the process down even more abruptly.

Wrap both launches in try { ... } catch (ActivityNotFoundException) { ... } and fall back to a short Toast (no_app_to_open_link). On the BackupWebView side the Toast is wrapped in withContext(Dispatchers.Main) since the catch fires on Dispatchers.IO.

Adds the matching no_app_to_open_link string so the message stays translatable. Happy path is unchanged.

DocsViewerActivity and BackupWebView both route tapped links to the
system browser with raw context.startActivity(intent) inside
shouldOverrideUrlLoading. If the device has no app that can handle
the link the call raises ActivityNotFoundException and the host
crashes mid-tap. In BackupWebView the call sits inside a
Dispatchers.IO coroutine, so the failure brings the process down
even more abruptly.

Wrap both in try/catch (ActivityNotFoundException) and fall back to
a Toast (no_app_to_open_link). On the BackupWebView side the Toast
is wrapped in withContext(Dispatchers.Main) since the catch fires
on Dispatchers.IO.
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.

DocsViewer and BackupWebView crash when no app handles a tapped link

1 participant