我需要每 30 秒调用一个方法,最好的方法是 Handler、Observable.interval() 还是有其他有效的方法
对于科特林:
Timer().scheduleAtFixedRate(timerTask {
// your code here
}, 30000, 30000
)
对于Java:
Runnable helloRunnable = () -> {
// your code here
};
ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
executor.scheduleAtFixedRate(helloRunnable, 0, 30, TimeUnit.SECONDS);