There is a myMethod(); method myMethod(); you need to run it after a certain time, let's say 45-60 seconds, tried to do it in

 new Timer().schedule(new TimerTask() { @Override public void run() { myMethod(); } }, 15000, 40000); / 

The timer is not accurate and sometimes the interval goes down to 2 seconds. If there are any other timers or some output, I would be very grateful.

  • Most likely the problem is in your code, or in any constraints like doze mode. In 20 minutes, the error from launch to launch did not go out in a few hundredths of a second. - temq
  • @temq and can it be a leaking of solder? t - elik
  • how do i find the problem ??? - elik
  • No, where is the leak? Even if it is, it can hardly affect the launch of the task. - temq
  • one
    Watch your code, look at what device it is in, in what situations, what kind of battery life magnifiers are on this device, for example doze mode on android 6+. - temq

1 answer 1

Alternatively, you can use CountDownTimer , just do not create a new one every time, but start or cancel it using the start() and cancel() methods, respectively