//1.声明变量 // 退出时间 private long currentBackPressedTime = 0; // 退出间隔 private static final int BACK_PRESSED_INTERVAL = 2000; // 2、重写onBackPressed()方法 @Override public void onBackPressed() { // 判断时间间隔 if (System.currentTimeMillis() - currentBackPressedTime > BACK_PRESSED_INTERVAL) { currentBackPressedTime = System.currentTimeMillis(); Toast.makeText(this, "再按一次返回键退出程序", Toast.LENGTH_SHORT).show(); } else { // 销毁 finish(); } }