I have a tabbed activity project with 3 webview pages in android studio In each fragment there is a webview I want to make every window can go back when webview canGoback

and if webview cant go back I want to activate Twice click to close app

private var doubleBackToExitPressedOnce = false
override fun onBackPressed() {
        if (webview1.canGoBack()){
            webview1.goBack()
        }else{
            if (webview2.canGoBack()){
                webview2.goBack()
            }else{
                if (webview3.canGoBack()){
                    webview3.goBack()
                }else{
                    if (doubleBackToExitPressedOnce){
                        super.onBackPressed()

                        doubleBackToExitPressedOnce = true
                        Toast.makeText(this, "Please click BACK again to exit", Toast.LENGTH_SHORT).show()
                        Handler().postDelayed({ doubleBackToExitPressedOnce = false }, 2000)
                    }
                }
            }
        }

    }

0 Answers