Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will TIME_TICK broadcast in deep sleep?

Tags:

android

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.

like image 507
Kevin K Avatar asked Jul 18 '10 06:07

Kevin K


2 Answers

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

like image 108
Emmanuel Avatar answered Nov 15 '22 00:11

Emmanuel


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.

like image 24
fredley Avatar answered Nov 15 '22 01:11

fredley