简体   繁体   English

前台服务是否在睡眠模式(而非打瞌睡模式)下存活?

[英]Does Foreground Service Survive Sleep Mode(not doze mode)?

So i have read a lot of posts about android services and their lifecycle during doze.所以我在打瞌睡期间阅读了很多关于 android 服务及其生命周期的文章。

So far:迄今为止:

Background Services are restricted by doze mode.后台服务受打瞌睡模式限制。

Foreground Services are immune from doze mode.前台服务不受打瞌睡模式的影响。 Meaning that they continue to have access network and etc.这意味着他们继续拥有访问网络等。

There are plenty posts about doze mode and foreground services and none of them are referring to what happens to foreground services when sleep mode kicks in.有很多关于打瞌睡模式和前台服务的帖子,但没有一篇提到睡眠模式启动时前台服务会发生什么。

Sleep Mode - means CPU will be sleeping and will not accept any command except from RIL(Radio Interface Layer) and alarms.睡眠模式- 意味着 CPU 将处于睡眠状态并且不会接受除 RIL(无线电接口层)和警报之外的任何命令。 CPU will go to sleep mode with in fraction of seconds after LCD is turned off. LCD 关闭后,CPU 将在几分之一秒内进入睡眠模式。

Doze Mode - means that apps on your phone will have no network access, the system will ignore “wakelocks” when apps try to keep the device from going to sleep, and no background tasks will be allowed to run.打瞌睡模式- 意味着您手机上的应用程序将无法访问网络,当应用程序试图阻止设备进入睡眠状态时,系统将忽略“唤醒锁”,并且不允许运行任何后台任务。 That certainly makes it sound like your phone won't do you much good, but there are a few ways Doze preserves functionality.这当然让人觉得你的手机对你没什么好处,但打瞌睡有几种方法可以保留功能。 While apps can't wake the device up to run sync jobs and other background tasks, high-priority push messages will still show up.虽然应用程序无法唤醒设备以运行同步作业和其他后台任务,但高优先级推送消息仍会显示。 So for example, a Hangouts message will appear on a device that's in Doze mode.例如,环聊消息将出现在处于打瞌睡模式的设备上。

App Standby - an app that goes into standby loses all network access and all its background sync jobs are suspended.应用待机- 进入待机状态的应用将失去所有网络访问权限,并且其所有后台同步作业都将暂停。 These restrictions are temporarily lifted when your phone is plugged in and for a few minutes every day or two.当您的手机插入电源时,这些限制会暂时解除,并且每隔一两天就会解除几分钟。 This gives suspended apps a chance to run any pending sync jobs, but they won't be allowed to continue running.这使暂停的应用程序有机会运行任何挂起的同步作业,但不允许它们继续运行。 A high-priority push notification will also be able to wake an app from standby for a short time.高优先级推送通知还可以将应用程序从待机状态唤醒一小段时间。

Questions:问题:

  1. Do foreground services also pause when in sleep mode?处于睡眠模式时,前台服务是否也会暂停? If yes, do they restart or continue from where it left off?如果是,他们是重新开始还是从中断的地方继续?
  2. Does the device even get to sleep mode when having a foreground service active?当前台服务处于活动状态时,设备是否会进入睡眠模式?

Foreground service still alive during Doze and Standby.在 Doze 和 Standby 期间,前台服务仍然存在。 I checked this.我检查了这个。 My app is local proxy with tcp sockets.我的应用程序是带有 tcp 套接字的本地代理。 But... network module is going to sleep.但是……网络模块要休眠了。 My proxy continues to work, port stays open but connection to network will be lost for the reason of network sleeping during Standby.我的代理继续工作,端口保持打开状态,但由于待机期间网络休眠,网络连接将丢失。 Simple push power button - and ups, packets begin to go out.简单地按下电源按钮 - 和起伏,数据包开始出去。 Now searching for wakeup device programmatically on connection timeout condition现在在连接超时条件下以编程方式搜索唤醒设备

Sleep mode is same as doze mode.睡眠模式与打瞌睡模式相同。 As foreground services are not affected by doze mode, so you should be fine using the foreground service.由于前台服务不受打瞌睡模式的影响,因此您应该可以正常使用前台服务。

Ex: running song using foreground service例如:使用前台服务播放歌曲

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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