Android doze mode and foreground service

后端 未结 1 1193
误落风尘
误落风尘 2021-01-29 03:08

I read many questions here about doze mode like Android doze mode, Android N Doze mode - how to keep background download and processing?, Wakelock and doze mode and many others.

相关标签:
1条回答
  • 2021-01-29 03:19

    According to this SO question and answer:

    In this post's comments on Sep 17 Dianne Hackborn writes:

    Apps that have been running foreground services (with the associated notification) are not restricted by doze.

    - Source (sec_aw)

    It looks like using a foreground service prevents the app from being killed by Doze.

    Please note though, that some vendors (I know of Samsung, but there are probably others) create their own RAM conservation/battery saving tools. These may exhibit patterns completely different from Doze, and there's usually a bunch of other hoops to jump through. You are not guaranteed to get the same behavior on these devices either - they may be more or less aggressive, and the more aggressive ones tend to be worse for keeping services or whatever alive.

    There's also no universal way to deal with these, but someone has made an entire website dedicated to showing what vendors are problematic, as well as potential workarounds. Note that the majority of the problematic vendors only yield end-user solutions, which means you (the developer) have no way to fix it without the user doing something.

    While this is unfortunate, that's pretty much what happens when companies implement their own versions of Android. Also, from my own experience (primarily as a user rather than a dev) on a Samsung phone, the settings aren't always respected and still causes annoying behavior.

    Anyway, as long as Doze is present, foreground services should be fine. On other vendors, however, all bets are off and you're at the mercy of the vendor's implementation of some type of optimization system. On certain exposed operating systems (again, see the website linked earlier), you also have no choice but to ask the user to fix certain settings to keep stuff alive.

    0 讨论(0)
提交回复
热议问题