WebFragment.shouldOverrideUrlLoading (app/src/main/java/com/meteocool/ui/map/WebFragment.kt:286) hands every non-meteocool URL off to a fresh startActivity:
override fun shouldOverrideUrlLoading(view: WebView?, url: String?): Boolean {
if (Uri.parse(url).host!!.contains("meteocool.com")) {
return false
}
Intent(Intent.ACTION_VIEW, Uri.parse(url)).apply {
startActivity(this)
}
return true
}
If the URL resolves to no installed Activity (no browser, an oddly-formed link, a custom scheme like mailto: on a device with no mail client, etc.) startActivity throws ActivityNotFoundException, which is uncaught here and brings down the map fragment. This is the U04 pattern from the WebView posture notes.
Suggested fix
Wrap the launch in a try { ... } catch (ActivityNotFoundException) { ... } and fall back to a short Toast so the fragment survives:
try {
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url)))
} catch (e: ActivityNotFoundException) {
Toast.makeText(requireContext(), R.string.cant_open_link, Toast.LENGTH_SHORT).show()
}
A PR with this change plus a cant_open_link string is open at #93.
WebFragment.shouldOverrideUrlLoading(app/src/main/java/com/meteocool/ui/map/WebFragment.kt:286) hands every non-meteocool URL off to a freshstartActivity:If the URL resolves to no installed Activity (no browser, an oddly-formed link, a custom scheme like
mailto:on a device with no mail client, etc.)startActivitythrowsActivityNotFoundException, which is uncaught here and brings down the map fragment. This is the U04 pattern from the WebView posture notes.Suggested fix
Wrap the launch in a
try { ... } catch (ActivityNotFoundException) { ... }and fall back to a short Toast so the fragment survives:A PR with this change plus a
cant_open_linkstring is open at #93.