点击两次back后再退出程序,有时候会对用户体验有好处,下面是一种十分简单的方法
1 2 3 4 5 6 7 8 9 10 11 12 13 |
private long exitTime = 0; @Override public boolean onKeyDown(int keyCode, KeyEvent event) { ExitApp(); return false; } public void ExitApp() { if ((System.currentTimeMillis() - exitTime) > 2000) { Toast.makeText(BackAppActivity.this, "再按一次退出程序", Toast.LENGTH_SHORT).show(); exitTime = System.currentTimeMillis(); } else { finish(); } |
0 条评论