1

I have been roaming in forums for days and all I found was same repeated responses which don't work at all. I am trying to set an alarm for a certain time (e.g. 8PM) to send a notification. However, as soon as I force close the app the alarm is also cleared. It works fine if app is running in the foreground or minimized. Peopled asked this in many other questions and received same questions that none of them work. I brought some of them in the following:

  1. use service(sticky or other types)
  2. use flag FLAG_INCLUDE_STOPPED_PACKAGES for the intent
  3. start service again in onDestroy or onTaskRemoved some other responses none of which seems to work. Do you know any best practice to set some alarms to send a notification at a certain time? it seems like this problems happens in some devices with restrictions like MIUIs. Thanks in advance for your responses.
Keivan.k
  • 548
  • 6
  • 21
  • Try using [WorkManager] (https://developer.android.com/topic/libraries/architecture/workmanager) instead. – segfault404 Jul 26 '20 at 10:22
  • Thanks, but is work-manager accurate? I read about it but it seems like work-manager doesn't do the task exactly on the specified time. – Keivan.k Jul 26 '20 at 10:35
  • Sorry, my bad ..you're right AlarmManager is the only option here. I had a similar problem too , but even WorkManager doesn't work when app is killed. Asked a similar question sometime back (https://stackoverflow.com/questions/62977846/notify-inactive-users-who-have-not-opened-the-app-for-7-days-even-if-android-a) – segfault404 Jul 26 '20 at 10:42
  • No it's fine. As I did my research I found the same result that using work manager is the best possible way to do this as alarm managers are cleared away when the app is closed. I don't know what is their point though. Thanks for your response. – Keivan.k Jul 26 '20 at 10:54

0 Answers0