-1

How can I create a service which will push a notification at a specific time everyday? I've been trying many method on google but they did not work well. Anyone know a good way to do this? Someone say its better to use AlarmManager, while some others say its should be JobScheduler because AlarmManager is deprecated. Anyone have a good reference?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Nguyen Hoang Vu
  • 751
  • 2
  • 14
  • 35

2 Answers2

0

If you want something to be executed on exact time then you should use AlarmManager.

Based on the documentation:

Standard AlarmManager alarms (including setExact() and setWindow()) are deferred to the next maintenance window.

  • If you need to set alarms that fire while in Doze, use setAndAllowWhileIdle() or setExactAndAllowWhileIdle().
  • Alarms set with setAlarmClock() continue to fire normally — the system exits Doze shortly before those alarms fire.

You cannot trigger something at specific time using JobScheduler. The execution of job is under OS control. The jobs will be deferred during doze mode hence trigger at exact time won't be possible.

Use JobScheduler when you want to ensure that a Job must be triggered within specific interval however the execution at exact time is not crucial.

Sagar
  • 23,903
  • 4
  • 62
  • 62
0

Set up a backend server for Push notification . When Api hit request to FCM for push request with device id then device will get notification. For Automatic push from backend , use cron from backend .A background process run in backend api and will hit FCM in some time interval and device will receive PUSH Notification.