两次按钮返回按钮,只在第二次按下时相应事件,并通知用户再次按下即可退出。
private static long back_pressed; @Override public void onBackPressed() { if (back_pressed + 2000 > System.currentTimeMillis()) super.onBackPressed(); else Toast.makeText(getBaseContext(), "Press once again to exit!", Toast.LENGTH_SHORT).show(); back_pressed = System.currentTimeMillis(); }