我正在使用此代码:
private static long back_pressed;
@Override
public void onBackPressed() {
if (back_pressed + 2000 > System.currentTimeMillis()) super.onBackPressed();
else Toast.makeText(getBaseContext(), "click again to leave", Toast.LENGTH_SHORT).show();
back_pressed = System.currentTimeMillis();
}
它只关闭当前的Activity,如何在单击两次后退按钮时关闭整个应用程序?
答案 0 :(得分:0)
您可以使用以下内容:
@Override
public void onBackPressed() {
if (back_pressed + 2000 > System.currentTimeMillis()) {
android.os.Process.killProcess(android.os.Process.myPid());
System.exit(1);
}
else Toast.makeText(getBaseContext(), "click again to leave", Toast.LENGTH_SHORT).show();
back_pressed = System.currentTimeMillis();
}