-1

I try to set up an alarm with Alarmmanager and fire a service five times. I try to fire it after 30 minutes after the time is set. After 1 hour, after 2 hours, 3 hours and 5 hours - but it does not really work...

I tried alarmmanager.setAlarmClock --> it does not work... alarmmanager.setExactAndAllowWhileIdle --> does not work ... I have no idea where the problem is.

I am using Android 8

2 Answers2

1

There are changes in oreo to improse battery etc. that limits your usage of background services. (Look at this)

You can use a foreground service instead (with an ongoing notification) You have to call startForegroundService() instead of startService() and call startForeground(ID, YOUR_NOTIFICATION) in the five seconds after the service is launched

Or you can use the JobScheduler (how to use it) that fire if some conditions are met (i.e. if you are connected to internet, if your device is charging, if your connection is unmetered, etc)

Good luck

Kilarn123
  • 723
  • 5
  • 6
0

You would not be able to run background services long running in Oreo as there are behaviour changes, now Oreo to optimise system memory, battery etc, it kills background service, to solve your issue you should use foreground service.

Also please have a look at: https://stackoverflow.com/a/50639788/5479863

Abdul Aziz
  • 442
  • 5
  • 12