Vinoth
Vinoth

Reputation: 5785

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() ?

Upvotes: 2

Views: 6135

Answers (2)

Cyrille GUIPIE
Cyrille GUIPIE

Reputation: 1

@Override
public onBackPressed(){
  if(webView.canGoBack()){
     webView.goBack();
   }else{
   super.onBackPressed();

Upvotes: 0

pjama
pjama

Reputation: 3044

Override the Activity's onKeyDown(..) event

@Override
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

Upvotes: 7

Related Questions