2

I am working on a task scheduling app that reminds me of a task at a certain time. I used to implement this with getSystemService(AlarmManager.class).set(RTC_WAKEUP, millis, pendingIntent);. Then a IntentService gets started later and shows a notification.

But in Android Oreo my IntentService simply doesn't get called at all. I noticed the massive discussion about the Background Execution Limits and how you should migrate from AlarmManager to JobScheduler, but nobody mentions how JobScheduler can start a job based on RTC.

What my IntentService does besides showing a notification is nothing more than setting the task as "notified" or "done", which I think is incomparable to the heavy tasks like synchronizing big amount of data over network that the JobScheduler was introduced for.

What is the best practice in Android Oreo to implement time-based notifications?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Sah
  • 1,017
  • 2
  • 11
  • 19
  • suggestion is to use Broadcast recievers . https://stackoverflow.com/questions/45815899/localnotification-with-alarmmanager-and-broadcastreceiver-not-firing-up-in-andro – Balu Sangem Jan 20 '18 at 12:56
  • use firebase job dispatcher – hemen Jan 20 '18 at 14:22
  • @notTdar could you give more information on how Firebase JobDispatcher can be used to schedule a task with RTC? – Sah Jan 20 '18 at 14:24
  • Jobs automatically takes care of waking your device, but if you want to go for exact time then use setAlarmClock and setExactWhileInIdle – hemen Jan 20 '18 at 14:32

1 Answers1

1

I am taking @balu-sangem 's solution:

  • Replace PendingIntent.getService() with PendingIntent.getBroadcast()
  • Replace IntentService with BroadcastReceiver
Sah
  • 1,017
  • 2
  • 11
  • 19