I have an alarm clock app on the play store that works very well on most of the devices , but unfortunately some devices report the alarm does not fire on the time adjusted and i concluded from research that there are some devices that restrict apps running in the background and kills alarm manager !
I have handled doze mode using the following code :
if (Build.VERSION.SDK_INT >= 23)
{
alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, timeStamp, pendingIntent);
}
else if (Build.VERSION.SDK_INT >= 19)
{
alarmManager.setExact(AlarmManager.RTC_WAKEUP, timeStamp, pendingIntent);
}
else
{
alarmManager.set(AlarmManager.RTC_WAKEUP, timeStamp, pendingIntent);
}
However this seems not enough on some devices.
I have read that a foreground service can prevent the system from killing the app anyway , however i can't ensure this also since i don't have in hand the devices where the problem occurs.
I want to ensure my alarm works perfectly fine on all devices and handles all scenarios , so what are all possible things to do to make sure my app runs properly and is not killed by the system?