簡體   English   中英

在協程中使用 webview 回調

[英]Using webview callbacks in coroutines

I have a situation where I have a suspend function in which I want to call a webview and receive data in its shouldOverrideUrlLoading and continue the coroutine after receiving the response in the webview URL.

我還沒有發現任何有用的東西。 所以我對如何實現這一點感到困惑。 另外,我將如何將線程從 Dispatchers.IO 切換到 Dispatchers.Main

所需內容的 Sudo 代碼

withContext(Dispatchers.Main) {
    call api1
    call api2

    launch webview in main thread
    get result from shouldOverrideUrlLoading

    call api3 with the result from above 
    return result of api3
}

您可以使用suspendCancellableCoroutine 它旨在以一種簡單的方式將回調 API 轉換為掛起函數。 您可以在此處找到一些如何使用它的示例: https://kt.academy/article/cc-cancellation

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM