睡着了Android设备的定义是什么? [英] What is the definition of asleep for an android device?

查看:191
本文介绍了睡着了Android设备的定义是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用

alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, 0, DURATION, broadcast);

要安排如果设备没有睡着,应该只执行的重复任务。据我了解在AlarmManager的 API 的意图会被调用一次设备从睡梦中醒来。

To schedule an repeating task that should only be executed if the device is not asleep. As I understand the API on the AlarmManager the intent will be called once the device wakes up from sleep.

现在,当是在Android设备睡着了吗?为了测试我设置的时间延长至2分钟,该设备连接到我的机器。现在我看logcat的,每两分钟就会吐出我的调试消息。

Now when is an Android device asleep? For testing I set the duration to two minutes and connected the device to my machine. Now I'm watching logcat and every two minutes it will spit out my debug message.

我始终认为,一个已停用的屏幕意味着设备开始睡觉。 或者是我在看调试输出$ P $睡觉pventing的设备? 我也断开了USB连接,半小时后看了看日志,我可以看到一个电话给我的计时器code即使显示是黑暗多于15分钟。

I always thought that an deactivated screen means that the devices starts sleeping. Or is my looking at the debug output preventing the device from sleeping? I also disconnected the USB connection and looked at the log after half an hour and I could see a call to my timer code even if the display was dark for more then 15 minutes.

我如何验证从该时间命令不执行了,并指AlarmManager文档中的哪些睡着了吗?有没有办法从logcat的输出看,当设备开始睡觉?

How can I verify from which time the command is not executed anymore and what asleep refers to in the AlarmManager documentation? Is there a way to see from the logcat output when the device started sleeping?

推荐答案

设备处于睡眠状态时,没有运行的应用程序,$睡觉p $ pvents它。所以: 1.屏幕处于关闭状态(虽然它在总有一些运行的应用程序,egLauncher) 2.没有正在运行的服务(如音乐,下载) - 没有CPU锁

Device is asleep when there is not running application that prevents it from sleeping. So: 1. The screen is off (while it's on there is always some running app, e.g.Launcher) 2. There is no running service (e.g. music, downloads) - no CPU locks.

AlarmManager唤醒设备进入休眠状态,跑什么跑。这是关键的例如到结束那是在广播接收器中创建的报警,使设备再次入睡的服务。如果你折腾更长,重要的背景,你应该为你的应用程序,以prevent从被杀害的Andr​​oid操作系统获取CPU锁。

AlarmManager wakes device from sleeping, runs what is to run. It's critical e.g. to ends a service that was created in broadcast receiver from alarm to let the device fall asleep again. If you do sth longer and important in the background you should acquire CPU lock for your app to prevent it from being killed by Android OS.

那你究竟是我如何验证从哪个时间该命令不执行了是什么意思?什么命令?

What do you exactly mean by "How can I verify from which time the command is not executed anymore"? What command?

从JavaDoc的:

注册警报被保留,而   该装置是睡着(和可   如果他们可选择唤醒设备   在这段时间去关闭),但将   如果它被关闭清除并   重新启动。

Registered alarms are retained while the device is asleep (and can optionally wake the device up if they go off during that time), but will be cleared if it is turned off and rebooted.

所以OS持有所有报警,设备可以由去,而它正在睡觉的闹钟唤醒。报警被重新启动后下降(你应该让他们在DB和重启后恢复它们)。

So OS hold all alarms, device can be waken up by the alarm that goes while it is sleeping. Alarms are dropped after reboot (you should keep them in DB and restore them after reboot).

有没有办法从logcat的输出看,当装置启动睡着了吗? 据我所知还没有,我只能看到事物一样,当屏幕熄灭:

"Is there a way to see from the logcat output when the device started sleeping?" As I know there isn't, I can only see sth like that when screen goes off:

*** set_screen_state 0 从权力的标签

恕我直言,你不应该过问睡眠模式,只是屏幕处理和关闭,如果需要的意图(Intent.ACTION_SCREEN_OFF)使您的应用程序的好公民的Andr​​oid,最终服务尽快,释放资源(网络,GPS,CPU)尽快,使用不准确的报警器,下载管理器,并通过操作系统把所有的好参谋。我认为,Android的处理CPU休眠透明。

IMHO you shouldn't bother about sleep mode, just make your app "good Android citizen" by handling screen off and on intents (Intent.ACTION_SCREEN_OFF) if needed, finishing services ASAP, releasing resources (network, GPS, CPU) ASAP, using inexact alarms, download manager, and all good staff brought by OS. I believe that Android handles CPU sleeps transparently.

这篇关于睡着了Android设备的定义是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆