Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Sleep stages/levels on an Android device?

Tags:

android

sleep

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?

like image 403
zer0stimulus Avatar asked Feb 15 '11 18:02

zer0stimulus


3 Answers

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?

  • An alarm from AlarmManager
  • An incoming phone call
  • An incoming text message
  • If you have a socket open on wireless data (not WiFi), an incoming packet on that socket

Those are the big ones. There might be others.

like image 193
CommonsWare Avatar answered Dec 08 '22 02:12

CommonsWare


I've noticed the following behaviour:

  1. You have your activity open and stop interacting with it
  2. 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.

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

like image 24
Pedro Loureiro Avatar answered Dec 08 '22 03:12

Pedro Loureiro


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.

like image 36
user728732 Avatar answered Dec 08 '22 04:12

user728732