androidandroid-webviewkotlin-coroutines

Android web-view reload is not reloading on reload click


 private fun reloadWebViewOnClick(){
        //webview reload
        lifecycleScope.launchWhenResumed {
            launch(Dispatchers.Main) {
                binding?.webview?.reload()
            }
        }
    }

I have tried log but controle never enter at reload scope. I am unable find what I am missing.


Solution

  • Please change launchWhenResumed to launch because launch will work only when the fragment resumes.

    private fun reloadWebViewOnClick(){
        //webview reload
        lifecycleScope.launch {
            launch(Dispatchers.Main) {
                binding?.webview?.reload()
            }
        }
    }