As i know you have to use deep
link
in shouldOverrideUrlLoading
, shouldOverrideUrlLoading
use for :
If a WebViewClient is not provided, by default WebView will ask
Activity Manager to choose the proper handler for the URL
In the other hands we can handle some situation when we open a web view in
shouldOverrideUrlLoading
fun
:
webView.webViewClient = object : WebViewClient() {
override fun shouldOverrideUrlLoading(view: WebView, request: WebResourceRequest): Boolean {
val url = request.url.toString()
if (url.startsWith("intent://")) {
try {
val intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME)
startActivity(intent)
} catch (error: ActivityNotFoundException) {
return false
}
return true
}
return false
}
}
Then in your situation :
I want to listen for this button click and finish the activity A and
open activity B if this happens.
You have to use deep
link
in shouldOverrideUrlLoading
:
When a clicked link or programmatic request invokes a web URI intent,
the Android system tries each of the following actions, in sequential
order, until the request succeeds:
-Open the user's preferred app that can handle the URI, if one is designated.
-Open the only available app that can handle the URI.
-Allow the user to select an app from a dialog.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…