Aug 18, 2011

Handle the Back button in WebView, to back in history.

Normally, we will have a Back button on browser, for user to go back in history. The default behaviour of the BACK button on Android system is Exiting the app. In order to change it's behaviour, we can override the onKeyDown() method: if it's BACK button pressed AND there has a back history item, than go back; otherwise pass to super method to handle as normal.

public boolean onKeyDown(int keyCode, KeyEvent event) {

if (keyCode == KeyEvent.KEYCODE_BACK){
return true;
return super.onKeyDown(keyCode, event);

Related Post:

- Display Progress Bar on WebView when loading


- Load local HTML from /assets

- Create your own London 2012 App

No comments:

Post a Comment

Infolinks In Text Ads