1

Google forces me to stop using the AlarmManager because of Excessive Wakeups. I should now use JobScheduler, but my app should support older devices with API <21. So I have to use the Firebase JobDispatcher :-(

However, in my opinion, the JobDispatcher is unreliable, unlike AlarmManager.

I set the interval to every 60 secs (1 min). But the gaps between JobService.onStartJob() are:

1, 10, 6, 1, 16, 12, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 12, 4, 0, 1, 8 mins.

If I set the interval to 10 mins, the gaps are:

11, 10, 10, 10, 10, 10, 21, 12, 10, 10, 10, 10, 10, 15, 10, 41, 10, 13, 14, 14, 22, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 19, 10, 10, 34, 14, 10, 10, 10, 12, 10 mins.

My smartphone (Samsung Galaxy Alpha, Android 5.0.1) is connected to power and not in standby, power safe option is deactivated.

What am I doing wrong?

FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(context));

Job jobWifi = dispatcher.newJobBuilder()
    .setService(ConnectionJobService.class)
    .setTag("tag")
    .setRecurring(true)
    .setLifetime(Lifetime.FOREVER)
    .setTrigger(Trigger.executionWindow(60, 60)) // 600, 600
    .setReplaceCurrent(true)
    .setRetryStrategy(RetryStrategy.DEFAULT_EXPONENTIAL)
    .setExtras(extras)
    .build();
almisoft
  • 2,153
  • 2
  • 25
  • 33
  • 1
    Doing anything every minute is going to kill the battery, yup. What are you actually trying to do? – ianhanniballake Jul 27 '17 at 22:19
  • "So I have to use the Firebase JobDispatcher" -- or Evernote's `android-job` library or various others. Moreover, excessive wakeups are not strictly tied to `AlarmManager` (rather, anything that wakes the device up frequently), and so it is unclear why you think "Google forces [you] to stop using `AlarmManager`". Bear in mind that Doze mode and app standby will make a mockery of your attempts to do something as frequently as you are testing, unless you are planning on users adding your app to the battery optimization whitelist. – CommonsWare Jul 27 '17 at 22:40
  • @ianhanniballake My app is connecting internet router to download incoming phone calls list over the internet. App user can choose refresh interval from 1 min. to 1 day. Because there is no push system available, so my app has to pull the data. The battery has not been drained excessively in the past by an app. – almisoft Jul 27 '17 at 23:05
  • @CommonsWare Google forces me stop using AlarmManager, see https://developer.android.com/topic/performance/vitals/wakeup.html: "Don't use AlarmManager to schedule background tasks, especially repeating or network background tasks. Use JobScheduler or Firebase JobDispatcher". There is an red exclamation mark in developer console - Android vitals. I'm afraid Google will depreciate my app in the Play Store if I do not fix the "Excessive Wakeups". So: My question is: Why is JobService.onStartJob() called not every minute or every 10 mins? – almisoft Jul 27 '17 at 23:16
  • @ianhanniballake I have just created a test app that just logs the start of onStartJob(), but does nothing else. First, the gaps are 1 minute, but later 10, 4, 1, 4, 3 minutes. Do you know why? – almisoft Aug 01 '17 at 14:31

0 Answers0