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);
}