简体   繁体   中英

Android AlarmManager Issue - Samsung Device

I'm trying to run a service for every 1 minute using AlarmManager with PendingIntent. With the use for setInexactRepeating function, i can able to run the service in all mobiles except Samsung Device , as far i tested till now.

Case 1: Android 5.1 - Below code runs every 1 Min in Samsung Device and later stage it turns to 5 mins interval

Case 2: Android 6.0 - Below code runs every 5 mins in Samsung Device and later stage it remains same

alarmMgr.setInexactRepeating(AlarmManager.RTC_WAKEUP, 1, 1000 * 60, alarmIntent);

Samsung Android 5.1 - Log

04-17 15:53:06.856 12381-13117/com.example.android.scheduler D/LL_LOG: loadFromNetwork
04-17 15:54:16.291 12381-13949/com.example.android.scheduler D/LL_LOG: loadFromNetwork
04-17 15:55:00.036 12381-14679/com.example.android.scheduler D/LL_LOG: loadFromNetwork
04-17 15:56:01.121 12381-15660/com.example.android.scheduler D/LL_LOG: loadFromNetwork
04-17 15:57:16.591 12381-16773/com.example.android.scheduler D/LL_LOG: loadFromNetwork
04-17 15:58:23.066 12381-17318/com.example.android.scheduler D/LL_LOG: loadFromNetwork
04-17 16:01:14.366 12381-19279/com.example.android.scheduler D/LL_LOG: loadFromNetwork
04-17 16:06:13.901 12381-25377/com.example.android.scheduler D/LL_LOG: loadFromNetwork

Samsung Android 6.0 Log

04-17 15:27:18.621 12920-31956/com.example.android.scheduler D/LL_LOG: loadFromNetwork
04-17 15:32:18.681 12920-5003/com.example.android.scheduler D/LL_LOG: loadFromNetwork
04-17 15:37:18.651 12920-9665/com.example.android.scheduler D/LL_LOG: loadFromNetwork
04-17 15:42:18.641 12920-10642/com.example.android.scheduler D/LL_LOG: loadFromNetwork
04-17 15:47:18.831 12920-11739/com.example.android.scheduler D/LL_LOG: loadFromNetwork
04-17 15:52:18.741 15868-15882/com.example.android.scheduler D/LL_LOG: loadFromNetwork
04-17 15:57:18.661 15868-17146/com.example.android.scheduler D/LL_LOG: loadFromNetwork

Notes: As said here ( AlarmManager not working on Samsung devices in Lollipop & Android exact Alarm is always 3 minutes off ) i have turned of APP Optimization.Still my issue remains same.

Im expecting to solve this or any alternatives to run service same way without battery drain.

You cannot use repeating alarms with this high frequency on most modern devices due to various power-saving mechanisms. Waking your device every minute will do bad things to the battery life.

However, if you really want to do it, you need to reschedule the alarm each time. Instead of scheduling a repeating alarm, just schedule a single alarm that will go off in a minute. When that alarm goes off, perform your processing and then schedule a single alarm that will go off 1 minute later. In this way you will be able to get accurate timing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM