Android Asynk Task在线程中运行

时间:2016-06-06 11:05:18

标签: android multithreading android-asynctask

我想每5秒运行一次asynk任务直到5分钟,我该怎么做? 我能够每5秒运行一次asynk任务,但不能限制5分钟

public void callAsynchronousTask() {
    final Handler handler = new Handler();
    Timer timer = new Timer();
    TimerTask doAsynchronousTask = new TimerTask() {
        @Override
        public void run() {
            handler.post(new Runnable() {
                public void run() {
                    try {
                        new CheckTxnStatusSTResult().execute(final_verification_card);
                        Log.d("dinesh","execute in every five seconds"+ final_verification_card);
                    } catch (Exception e) {

                    }
                }
            });
        }
    };
    timer.schedule(doAsynchronousTask, 0, 15000);

}

1 个答案:

答案 0 :(得分:0)

你可以这样做

public void FunctionName() {
    new CountDownTimer(Total_time, 1000) {
        @Override
        public void onTick(long millisUntilFinished) {
            MyUtils.Log("execute in every one seconds");
            // Display Data by Every Ten Second
        }

        @Override
        public void onFinish() {
           // Call Other function on Function
        }

    }.start();
}