How to repeat a task after a fixed amount of time in android?

后端 未结 5 1808
耶瑟儿~
耶瑟儿~ 2020-12-08 02:41

I want to repeatedly call a method after every 5-seconds and whenever I wish to to stop the repeated call of the method I may stop or restart the repeated call of the method

5条回答
  •  北荒
    北荒 (楼主)
    2020-12-08 03:16

    use TimerTask to call after specific time interval

        Timer timer = new Timer();
        timer.schedule(new UpdateTimeTask(),1, TimeInterval);
    

    and

      class UpdateTimeTask extends TimerTask {
    
            public void run() 
               {        
                // do stufff
               }
    
            }
    

提交回复
热议问题