Will TIME_TICK broadcast in deep sleep?

2020-04-05 06:48发布

Does Android wake from deep sleep in order to broadcast ACTION_TIME_TICK? 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:

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. 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.

标签: android
2条回答
Bombasti
2楼-- · 2020-04-05 07:25

I looked into the Android code. No this broadcast will not wake up the phone. It uses an AlarmManager.RTC type Alarm to broadcast time change.

Why do you need to be notified literally every minute?

How about setting up your own Alarm using the AlarmManager.RTC_WAKEUP type?

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

查看更多
▲ chillily
3楼-- · 2020-04-05 07:51

A better experiment: Instead of updating a TextView which you cannot see when the phone is off, write to the Log with:

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

You can keep an eye on this in Logcat while your phone is asleep.

查看更多
登录 后发表回答