How to set a timer in android

前端 未结 13 1728
天命终不由人
天命终不由人 2020-11-22 06:43

What is the proper way to set a timer in android in order to kick off a task (a function that I create which does not change the UI)? Use this the Java way: http://docs.ora

13条回答
  •  -上瘾入骨i
    2020-11-22 07:04

    As I have seen it, java.util.Timer is the most used for implementing a timer.

    For a repeating task:

    new Timer().scheduleAtFixedRate(task, after, interval);
    

    For a single run of a task:

    new Timer().schedule(task, after);
    


    task being the method to be executed
    after the time to initial execution
    (interval the time for repeating the execution)

提交回复
热议问题