在我的Android应用程序中,我编码是这样的;对于webview而言,这不是一个功能。单击BackButton导致应用重启。
请帮帮我
@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);
}
答案 0 :(得分:0)
如果我理解正确,则需要禁用后退按钮。
请尝试以下代码:
@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);
}
或者
@Override
public void onBackPressed() {
// Do Here what ever you want do on back press;
}