定时器任务在第一次运行后停止调用 run 方法

问题描述

我是编程新手,我正在做一个 android 应用程序,我有一个要求,我需要监视 30 多岁的一些日志。我正在使用计时器任务,但是发生了什么,如果 30 秒结束并且一旦终止就执行 run 方法,则计时器任务不会重复。

这是我的代码:

connectivityTimerTask = new ConnectivityTimerTask();
timer = new Timer(true);
//timer = new Timer(); // tried with this but it is not working
timer.schedule(connectivityTimerTask,30 * 1000);

定时器任务:

public class ConnectivityTimerTask extends TimerTask {

        @Override
        public void run() {
            Log.error("----- ACK NotReceived -----" + System.currentTimeMillis());
            //resetMonitor(); using this method I am setting the timer again
        }
    }

我想知道安排重复时间的最佳做法是什么。 我使用正确的方法吗?我可以使用 resetMonitor() 方法吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)