Vinoth Vinoth - 1 year ago 148
Android Question

Android webview back button

In my app when user clicks on a gallery widget i open the image in a webview as it supports zoom functionality.

Now when user clicks back button on webview i want the user to see my application. But it goes directly to home screen.

How should i handle the onBackKeyPressed() ?

Answer Source

Override the Activity's onKeyDown(..) event

public boolean onKeyDown(int keyCode, KeyEvent event) {

    if (keyCode == KeyEvent.KEYCODE_BACK) {
        // close image gallery
        return false; // this avoids passing to super

    return super.onKeyDown(keyCode, event);

*edit: code

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download