Is there a notion of sleep stages/levels on Android?
From browsing the mailing lists, I'm aware that there exist a stage called "Deep Sleep". Do execution for all apps halt when device reaches this state? If so, besides user hitting the power button, what else could wake the device back up?
From browsing the mailing lists, I'm aware that there exist a stage called "Deep Sleep".
There is not really a separate stage called "deep sleep". There is only "awake", "asleep", and "off".
Do execution for all apps halt when device reaches this state?
Execution of all processes ceases when the device goes to sleep or is powered off.
If so, besides user hitting the power button, what else could wake the device back up?
AlarmManager
Those are the big ones. There might be others.
I've noticed the following behaviour:
After a few seconds (it depends on how the device is configured) the screen will go off.
When the screen goes off, onSaveInstance
and onPause
are called.
A few seconds later (usually ~15s) the device enters into sleep mode (is this the correct name?)
When this happens, the following methods are invoked: onStop
(calling isFinishing
returns false), onRetainNonConfigurationInstance
and onDestroy
.
So far so good. Now, the strange behaviour begins: just after the last onDestroy
finishes, another activity is created: onCreate
, onStart
, onRestoreInstanceState
, onResume
and finally onPause
are invoked.
I find no reason for this strange behaviour. Why would another activity be created just to go straight to pause mode? This happens immediatly after onDestroy
of the original activity!
This was tested on Galaxy S. I didn't test what happens after a few hours with no activity. I'm not sure if anything else will happen.
I hope this will help you.
A short addition to the commonsware's list. After looking for a way to run methods periodically while phone is asleep, I've found out that TimerTask
functions during sleep mode.
TimerTask
is, in my experience, easier to work with if all you want is to run methods from a service and not to start an activity.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With