2

I am using AlarmManager in our app to set alarms that are set at specific date and time. Now recently few users of our app are complaining that these alarms are not popping up. Also, in Android O guidelines, it is mentioned that app should not run any background service and instead should switch to Firebase JobDispatcher. I have following 2 questions

  1. In our app, we do not do any background task except to show notification to user at the specified time and date. Even in this case, should we switch to Firebase Jobdispatcher?
  2. In case we do need to switch to JobDispatcher, how can the Job be set to run at exactly specific date and time?
Yossi
  • 11,778
  • 2
  • 53
  • 66
MonicaR
  • 21
  • 1

1 Answers1

0

Because you're not doing any background tasks like network requests or long running CPU operations, I think you should continue using Alarm Manager.

Now recently few users of our app are complaining that these alarms are not popping up.

This is because when doze mode triggers, it is not guaranteed that your alarms will be triggered(see this).

What you can do is use setAndAllowWhileIdle() or setExactAndAllowWhileIdle() methods from AlarmManager class as per your requirement for API level >= 23.

According to the documentation these are appropriate for notification purposes. setAndAllowWhileIdle() documentation:

Like set(int, long, PendingIntent), but this alarm will be allowed to execute even when the system is in low-power idle modes. This type of alarm must only be used for situations where it is actually required that the alarm go off while in idle -- a reasonable example would be for a calendar notification that should make a sound so the user is aware of it. When the alarm is dispatched, the app will also be added to the system's temporary whitelist for approximately 10 seconds to allow that application to acquire further wake locks in which to complete its work.

Yash Verma
  • 64
  • 1
  • 7
  • Thanks Yash for the reply. Not able to solve completely. Many devices like RedMi Note 4 have an issue. If a user kills the app from background, then notifications do not show up. In such cases, user has to explicitly whitelist the app from settings. Even Samsung has smart manager that disables your app if its inactive for more than 2-3 days – MonicaR Mar 09 '18 at 08:14
  • For Xiaomi devices, you need to have the autostart permission otherwise your app will be killed if the user clears it from the recent apps. You can take ask the user to grant this permission. For other devices, see this https://github.com/dirkam/backgroundable-android – Yash Verma Mar 10 '18 at 09:12
  • We are doing that, but asking user to grant permissions is not a seamless flow. – MonicaR Mar 11 '18 at 12:36
  • Yes, That's not a seamless flow and even I suffer from that in my apps. However, as per the following link, it can't be removed without getting whitelisted ny Xiaomi. https://stackoverflow.com/a/39476850 – Yash Verma Mar 11 '18 at 19:57
  • @MonicaR Did you solve the autostart permission issue in Mi devices? – Yash Verma May 31 '18 at 05:50
  • We have fixed the issue in a different way, since we just needed to show an alarm and did not need to make any network call, we have removed the use of intent service and instead used an explicit broadcastreceiver. This has solved the problem and now alarms show up on Mi devices too though autostart is not enabled, – MonicaR Jun 01 '18 at 07:40