Android之CountDownTimer定時器的使用
阿新 • • 發佈:2018-11-01
package com.cn.zyf.broadcastaccept; import android.os.Build; import android.os.CountDownTimer; import android.support.annotation.RequiresApi; import android.util.Log; /** * 定時器 * Created by zhang on 2018/6/15. */ public class BaseTimer { public static int time=15; //超時時間設定 public static Boolean overTimeHandleMethod(long time){ final boolean[] flag = {true}; CountDownTimer timer=new CountDownTimer(time*1000,1000) { @Override public void onTick(long l) { } @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN) @Override public void onFinish() { flag[0] =false; Log.d("ioservice", "超時以後的操作-----就是關閉放在這個位置寫。。。。"); BaseNotification.getNotification("連線超時,自動關閉"); } }; timer.start(); return flag[0]; } public static void whileTimeTest(){ while (true){ overTimeHandleMethod(5); } } }