I have a web view that lets me browse through a site. When i click the back button, rather than it going to the previous page it exits the app. I have added the following method to MainActivity.java
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
setContentView(R.layout.activity_main);
WebView webview = (WebView) this.findViewById(R.id.webView);
if (event.getAction() == KeyEvent.ACTION_DOWN) {
switch (keyCode) {
case KeyEvent.KEYCODE_BACK:
if (webview.canGoBack()) {
webview.goBack();
} else {
finish();
}
return true;
}
}
return super.onKeyDown(keyCode, event);
}