1

I have two activity let A and B. A is listActivity and B is webViewActivity. Now in webview, when i back pressed then it works fine within webview but in last back pressed, it resides in activity B but I want to go back to Activity A (listActivity). My code for back pressed

public boolean onKeyDown(int keyCode, KeyEvent event) {
        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);
    }

Thanks.

dheerajraaj
  • 124
  • 13
  • what about to implement `onBackPressed(.....)` in Activity – M D Jan 20 '15 at 13:23
  • @MD I think onBackPressed and onKeyDown(with KeyEvent.ACTION_DOWN) are same. if i am wrong plese correct me and what i have to write in onBackPressed(). – dheerajraaj Jan 20 '15 at 13:28
  • possible duplicate of [Android Overriding onBackPressed()](http://stackoverflow.com/questions/18337536/android-overriding-onbackpressed) – M D Jan 20 '15 at 13:30
  • @MD public void onBackPressed() { if(webView.canGoBack()) { webView.goBack(); } else { super.onBackPressed(); } } its not fulfil my requirement. Its working same as before. – dheerajraaj Jan 20 '15 at 13:34

2 Answers2

1

This may help you...

http://rickluna.com/wp/2014/04/disable-android-back-button-in-inappbrowser/

here it explains that you can disable back button in webview... so make this works in your logic.

-3
    @Override
    public void onBackPressed() {

         super.onBackPressed();
    }

onbackpressed function call when you pressed back button then finish current activity.

hareesh J
  • 520
  • 1
  • 6
  • 21
  • Overriding a method and providing an implementation where you call the method in the super class is complete nonsense. This does absolutely nothing useful. – David Wasser Jan 20 '15 at 17:38