-1

I have implement following code in my application, but not executing on specific time. I want to run a task on every 1 minute interval while app is in Background.

    WorkManager workManager = WorkManager.getInstance();
    List<WorkStatus> value = workManager.getStatusesByTag(CALL_INFO_WORKER).getValue();
    if (value == null) {

       PeriodicWorkRequest callDataRequest1 = new PeriodicWorkRequest.Builder(CallInfoWorker.class,10,TimeUnit.SECONDS,3, TimeUnit.SECONDS).build();
        workManager.enqueue(callDataRequest1);
    }

1 Answers1

1

First of all its not a great idea to execute some task so frequently. Second minimum interval for periodic request is around 15 minutes.

Even if you find some work around to execute tasks frequently, it won't work from Android O which limits background execution

Sagar
  • 23,903
  • 4
  • 62
  • 62
  • I checked for 15 min it is working in nexus like devices but not working in other devices like one plus, LG,Moto G etc , Is there anything different to work on this devices. – Jitendra Keshari Jun 15 '18 at 10:24
  • In my application, i want to update user LatLong on server in every one minutes interval while app is in background or foreground state, can you suggest best Background service Api that full fill my requirement. – Jitendra Keshari Jun 15 '18 at 10:36
  • Best you can do is create Foreground service. But this wont help either on Android O. You should change the interval to 15 mins rather than 1 min – Sagar Jun 15 '18 at 10:57
  • Thanks sagar, please share the link for foreground service which is working below Android O. – Jitendra Keshari Jun 16 '18 at 12:27
  • You can follow this [SO](https://stackoverflow.com/questions/43251528/android-o-old-start-foreground-service-still-working) – Sagar Jun 16 '18 at 12:57