1

I used to start LocationService with following command

startService(new Intent(MainActivity.this, LocationUpdateService.class));

but since Oreo does not support it, I moved to JobSchedular and now i do this.

final int hourly = (int)TimeUnit.HOURS.toSeconds(1); 
final int toleranceInterval = (int) TimeUnit.MINUTES.toSeconds(15);

    Job job = dispatcher.newJobBuilder()
                .setLifetime(Lifetime.FOREVER)
                .setService(LocationUpdateService.class)
                .setTag("LocationJob")
                .setRecurring(true)
                .setReplaceCurrent(true)
                .setTrigger(Trigger.executionWindow(hourly,toleranceInterval))
                .build();
        return job;


    FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(this));
    Job job=createJob(dispatcher);
    dispatcher.schedule(job);

Initially my location service was used to send me user's lat/lng after every 1 hour. Now with FirebaseJobDispatcher i scheduled this job, and it runs Location service after every 1 hour. So what's the difference is there actually?

In both cases my location service is doing network operation and sending user's lat/lng after every 60 minutes. I want to know what performance gain we get when using JobSchedular

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
dev90
  • 7,187
  • 15
  • 80
  • 153
  • 1
    "but since Oreo does not support it" -- yes, it does. You can start services using `startService()` on Android 8.0+. "I moved to JobSchedular and now i do this" -- your code is using Firebase Job Dispatcher, not `JobScheduler`. "So what's the difference is there actually?" -- since we cannot see the implementation of your `LocationService`, we cannot tell you much about it. – CommonsWare May 28 '18 at 12:14
  • @CommonsWare: sorry my bad, in Oreo, `startService()` will not work if app is background, but `Firebase Job Dispatcher` will still work, so my question is why android prefer `Firebase Job Dispatcher` and not normal services in Oreo for background tasks, when they both are doing the same thing for me, I am still able to send user lat/lng to server after every 1 hour when app is in background, by using `Firebase Job Dispatcher` – dev90 May 28 '18 at 12:16
  • Android does not "prefer" Firebase Job Dispatcher, as it is not part of Android. That is a third-party library from Google. `startService()` and Firebase Job Dispatcher are not "doing the same thing". It is certainly possible that you have a service that you could re-implement using Firebase Job Dispatcher (or `JobScheduler`, or `WorkManager`, or perhaps even `AlarmManager`). However, we cannot comment on that, since we do not have the implementation of your service. – CommonsWare May 28 '18 at 12:21

0 Answers0