Android设备-功能按钮-双击退出

/**
 * 双击退出功能是否生效(默认ture)
 */
private boolean DOUBLECLICK_EXIT = true;

/**
 * 双击退出函数
 */
private long firstTime = 0;
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) { if (DOUBLECLICK_EXIT) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) { if (System.currentTimeMillis() - firstTime > 2000) { Toast.makeText(mContext, "再按一次退出程序", Toast.LENGTH_SHORT).show(); firstTime = System.currentTimeMillis(); } else { finish(); System.exit(0); } return true; } } return super.onKeyDown(keyCode, event); }

 

posted @ 2021-05-06 10:36  寒水易兮萧萧风  阅读(91)  评论(0编辑  收藏  举报