-3

In my android application, I have coded like this; which is not fuctional for webview. On clicking BackButton leading to app restart.

Please help me

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {

if ((keyCode == KeyEvent.KEYCODE_BACK) && view!=null && view.canGoBack()) {

    view.goBack(); // go back in only the web view
    return true;
}


else  if ((keyCode == KeyEvent.KEYCODE_BACK)) { //Back key pressed

        if(counter<1)
        {

            Toast.makeText(this, "Press the back button one more time to quit the app",Toast.LENGTH_LONG).show();
            counter++;
        }
        else
        {
            Intent intent = new Intent(getApplicationContext(), LaunchActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            intent.putExtra("EXIT", true);
            startActivity(intent);
        }

        return true;
    }
    return super.onKeyDown(keyCode, event);
}
Phoenix Haroz
  • 333
  • 1
  • 4
  • 9

1 Answers1

0

If I understand correct then you need to disable back button.

Try the following code:

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
     if (keyCode == KeyEvent.KEYCODE_BACK) {
     //preventing default implementation previous to android.os.Build.VERSION_CODES.ECLAIR
     return true;
     }
     return super.onKeyDown(keyCode, event);    
}

Or

@Override
public void onBackPressed() {
    // Do Here what ever you want do on back press;
}
Amsheer
  • 7,046
  • 8
  • 47
  • 81