I am coding an app with Android Studio. I started a few days ago.
I want to put a WebView in a fragment. Because I use Fragment
to present WebView I cannot override onBackPressed
to handle back button events. I'm trying to achieve the behaviour of opening previous page of WebView when back button pressed.
I found this code:
@Override
public void onBackPressed(){
if(webView.canGoBack()){
webView.goBack();
}
else{
super.onBackPressed();
}
}
But this doesn't work in a fragment. Can someone help me with this example or in general how I could write my normal code in the fragment class.