android 碎片

1、双击退出

方法1、

 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         }

方法2、

 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         }

 2、Toast 提示

	public void showToast(String text, int time){



		if(mToast!=null)

		{

		    mToast.setText(text);    

		}

		else

		{

			mToast=Toast.makeText(mContext,text,time);

		} 

		mToast.show(); //显示toast信息

	}

  

你可能感兴趣的:(android)