androidwebwebviewactivity-transition

Optimize Webview in Android App


when we add an an activity with a webview in it , it will load the website. But when we click some links on the webpage we gets redirected to some other page.Now if we press the back button, instead of redirecting back to the previous webpage, it redirects to the previous activity How can we fix that?


Solution

  • override this :

    @Override
    public void onBackPressed() {
        if (webView.canGoBack())
            webView.goBack();
        else
            super.onBackPressed();
    
    }