How to implement back in the Android Webview

2

I have an Android Activity with just a webview inside. For example:     

<WebView
        android:id="@+id/webview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"/>
</FrameLayout>

How do I make the webview back to the previous screen when I click the physical button to return from the phone?

    
asked by anonymous 19.03.2014 / 21:49

1 answer

1

You need to override the back event of your Activity and implement the back of the webview if it can return. For example:

@Override
public void onBackPressed() {
    if (this.webView.canGoBack()) {
        this.webView.goBack();
    } else {
        this.finish();
    }
}
    
19.03.2014 / 21:49