How to implement back in Android Webview

Asked

Viewed 1,054 times

2

I have an Android Activity with only one webview inside. For example:

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

How do I get the webview back to the previous screen when I click the physical back button of the phone?

1 answer

1

You need to overwrite the event of coming back from your Activity and implement the coming back from the webview if it can come back. For example:

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.