简体   繁体   English

TIME_TICK会在深度睡眠中播出吗?

[英]Will TIME_TICK broadcast in deep sleep?

Does Android wake from deep sleep in order to broadcast ACTION_TIME_TICK ? 为了广播ACTION_TIME_TICK Android是否会从深度睡眠中唤醒? From experimenting, I don't think it does, but I'm looking for a definitive answer. 从实验来看,我认为不是,但我正在寻找一个明确的答案。

My experiment involved registering a simple BroadcastReceiver to update a TextView on receive: 我的实验涉及注册一个简单的BroadcastReceiver来更新接收时的TextView

registerReceiver(new BroadcastReceiver() {
    int ctr = 0;
    @Override
    public void onReceive(Context context, Intent intent) {
        testView.setText("Time ticks: " + ++ctr);
    }
}, new IntentFilter(Intent.ACTION_TIME_TICK));

At 4 ticks, I turned off the screen for about 5 minutes, then turned it back on, and it read 6 ticks. 在4个刻度处,我关闭了屏幕大约5分钟,然后将其重新打开,它读取了6个刻度。 At 13 ticks, I turned the screen for 10 minutes, then turned it back on, and the number of ticks read 14. It only seems to increase by 1-2 ticks no matter how long I leave the phone off, which is why I suspect it doesn't broadcast the action during deep sleep. 在13个刻度时,我将屏幕旋转了10分钟,然后将其重新打开,并且刻度数读数为14.无论我多长时间离开手机,这似乎只会增加1-2个刻度,这就是为什么我怀疑它不会在深度睡眠期间播放动作。

I looked into the Android code. 我查看了Android代码。 No this broadcast will not wake up the phone. 没有这个广播不会唤醒手机。 It uses an AlarmManager.RTC type Alarm to broadcast time change. 它使用AlarmManager.RTC类型Alarm来广播时间变化。

Why do you need to be notified literally every minute? 为什么你需要每分钟通知字面?

How about setting up your own Alarm using the AlarmManager.RTC_WAKEUP type? 如何使用AlarmManager.RTC_WAKEUP类型设置自己的警报?

WARNING : Doing it every minute is will drain your battery. 警告 :每分钟都要耗尽电池电量。 I suggest doing it less often, like every hour. 我建议不要经常这样做,比如每小时。

Please let me know if this is helpful. 如果这有用,请告诉我。

Emmanuel 灵光

A better experiment: Instead of updating a TextView which you cannot see when the phone is off, write to the Log with: 一个更好的实验:不要更新手机关闭时无法看到的TextView ,而是使用以下命令写入日志:

Log.v("Tick","Total ticks: " + ++ctr);

You can keep an eye on this in Logcat while your phone is asleep. 当您的手机处于睡眠状态时,您可以在Logcat中留意这一点。

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

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