Android AlarmManager does not work on some devices when the application is closed

I try to start the IntentService as such from AlarmManager setRepeating() every half hour. I want to send a broadcast, from broadcast service to intent. The service will implement some functionality.

But first, AlarmManager does not start while the application is in a closed state.

When my application is running or in the background, the alarm works fine, and when I close the application, the alarm doesn’t work on some devices .

What to do to start the alarm, even if the application is closed?

+10
android
Sep 28 '16 at 6:33
source share
4 answers

From the documentation of setRepeating() :

As with API 19, all repeated alarms are inaccurate.

In addition, setRepeating() does not work with Doze .

You must use accurate alarms (set using the appropriate AlarmManager method based on the device API level):

 if (Build.VERSION.SDK_INT >= 23) { alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, triggerTime, intent); } else if (Build.VERSION.SDK_INT >= 19) { alarmManager.setExact(AlarmManager.RTC_WAKEUP, triggerTime, intent); } else { alarmManager.set(AlarmManager.RTC_WAKEUP, triggerTime, intent); } 

And reschedule them every time they fire.

NOTE. As mentioned in a comment above, some manufacturers (such as Xiaomi or Huawei) may implement certain battery saving features that can prevent alarms and cannot be bypassed programmatically.

+13
Sep 28 '16 at 6:45
source share

Money devices now come with more protection in the context of battery power consumption. By default, the device supports almost all applications in power saving mode. This means that in some devices background work (Location, Alarm manager) will not work, as soon as you exit the application, in some devices background tasks will not work after the battery limit (for example, 13%). Therefore, you need to leave your application in this battery saving mode to smoothly launch the application even in the background. You can do it for different manufacturers like ..

1. For Xioami

-> Go to battery → Power → Battery saver → your application Now select “No restrictions” (for background settings), then “Allow” for “Background location”

-> Autostart application after loading → Go to security application → Permissions → Automatically launch and check your application

2. For Samsung

- → Samsung Smart Manager application to stop background work after 3 days if you have not come to your application. Therefore, disable this feature for your application. Go to the application → Battery → Part (application energy saving tab) → click on your application and select disconnect

For other devices, there should be the same power parameters either in the parameter settings directly, or some application for its processing.

+7
Dec 06 '16 at 9:41
source share

for Lenovo Phone: -

you need to enter the settings → application-> select application-> uncheck the Limit box to start

now it will work in the background as a killed state

0
Sep 21 '17 at 13:25
source share

The following behavior has changed after fully charged. Previously, after turning off the power saving for this application, he showed that the batteries are not active, etc., but only after fully charging (due to the very low battery condition) the device worked as it should. Therefore, change these settings for the application, and then perform a full recharge (possibly only after the battery has previously been discharged). It can fix it.




ZTE Blade L110

Even with the battery disconnected (Settings → Battery → Settings → Battery), and the application is marked as important for messages (Settings → Request and notification → Application notifications → application name → Priority), neither setAlarmClock nor setAlarmClock starts on time.

0
Oct 31 '17 at 19:46
source share



All Articles