-1

I am working on GPS tracking Application in which I need to track location after 15 seconds. I have use handler to start service from onStartCommand() from Service class. but After 15 second or after some time after it handler does not execute always. I have also used WakeLock to prevent app from sleeping. how to overcome this issue?

2 Answers2

0

In short:

new Handler().postDelayed(() -> { ... }, 15000);

The action (lambda here) will be executed after the timeout (15,000 ms.)

Expanded it might look like this:

new Handler().postDelayed(new Runnable() {
    @Override
    public void run() {
        //Track my location
    }
}, 15_000);
Nick Cardoso
  • 20,807
  • 14
  • 73
  • 124
-1

Use Timer instead of Handler as shown below

new java.util.Timer().schedule(new java.util.TimerTask() {
            @Override
            public void run() {
                //do your task here
            }
        }, 15000);