Call Particular Method after regular interval of time

前端 未结 2 1632
青春惊慌失措
青春惊慌失措 2020-12-31 12:30

In my android application I want to call particular method at regular interval of time ie. \"after every 5 seconds\"...how can i do that....?

2条回答
  •  误落风尘
    2020-12-31 13:19

    You can use Timer for the fixed-period execution of a method.

    Here is a sample of code:

    final long period = 0;
    new Timer().schedule(new TimerTask() {
        @Override
        public void run() {
            // do your task here
        }
    }, 0, period);
    

提交回复
热议问题