in my Android project i've created an custom clock widget with a service which contains an instance of Broadcast Reciever and an intent filter. The Broadcast Reciever provides the update of the widget every time arrives the ACTION_TIME_TICK. This is working perfectly when set targetSdkVersion to 25, in gradle. But if i target to sdk 27, the service stops after few minutes. I've read the documentation about background executions limit in Android O, but i can't find any approach that is useful for my project. Do you have any suggestion?
There are a couple of things you can try which, when used in concert, should be able to cut through all of the idle/standby/doze modes (irrespective of OS version).
WakefulBroadcastReceiver
instead of an ordinary BroadcastReceiver
. Make sure you include the WAKE_LOCK
permission to use it correctly. Use the setExactAndAllowWhileIdle()
method (on API 23 & above) to schedule the Intent for the receiver:
if (Build.VERSION.SDK_INT < 23) { if (Build.VERSION.SDK_INT >= 19) { setExact(...); } else { set(...); } } else { setExactAndAllowWhileIdle(...); }
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.