android 双击退出

方法1、

android 双击退出
 1 rivate int mBackKeyPressedTimes = 0;
 2 
 3         @Override
 4         public void onBackPressed() {
 5                 if (mBackKeyPressedTimes == 0) {
 6                         Toast.makeText(this, "再按一次退出程序 ", Toast.LENGTH_SHORT).show();
 7                         mBackKeyPressedTimes = 1;
 8                         new Thread() {
 9                                 @Override
10                                 public void run() {
11                                         try {
12                                                 Thread.sleep(2000);
13                                         } catch (InterruptedException e) {
14                                                 e.printStackTrace();
15                                         } finally {
16                                                 mBackKeyPressedTimes = 0;
17                                         }
18                                 }
19                         }.start();
20                         return;
21                       else{
22                                this.activity.finish();
23                             }
24                 }
25                 super.onBackPressed();
26         }
android 双击退出

方法2、

android 双击退出
 1   private long exitTime = 0;
 2 
 3         public void ExitApp()
 4         {
 5                 if ((System.currentTimeMillis() - exitTime) > 2000)
 6                 {
 7                         Toast.makeText(this.activity, "再按一次退出程序", Toast.LENGTH_SHORT).show();
 8                         exitTime = System.currentTimeMillis();
 9                 } else
10                 {
11                         this.activity.finish();
12                 }
13 
14         }
android 双击退出

android 双击退出,布布扣,bubuko.com

android 双击退出

上一篇:①计划中的安卓(求大家帮我参考参考)


下一篇:redis中AOF的no-appendfsync-on-rewrite参数详解