1

Hi I am developing android application in which I am trying to load web view.

webView.loadDataWithBaseURL(targetUrl, object.toString(), "text/html", "utf-8", null);

inside my webview I have another link inside page. Once user click on the link it renders next page. Now problem is that from here if user click device back button it renders blank page. Not rendering any web page.

if (webView != null && webView.canGoBack()) {
        webView.goBack();
    } else {
        Intent i = new Intent(this, another.class);
        startActivity(i);
        finishActivity();
    }

How to handle this thing. Need some help. Thank you.

nilkash
  • 7,408
  • 32
  • 99
  • 176

2 Answers2

0

try this code :

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        switch (keyCode) {
            case KeyEvent.KEYCODE_BACK:
                if (mWebView.canGoBack()) {
                    mWebView.goBack();
                } else {
                    //do any thing else.
                }
                return true;
        }

    }
    return super.onKeyDown(keyCode, event);
}
Saeed Halawani
  • 127
  • 1
  • 4
0

have you try Chrome custom tabs ? try to use Chrome custom tab not webview

try this tutorial

Hamza
  • 2,017
  • 1
  • 19
  • 40