Qwertie
Qwertie

Reputation: 17176

Why does Android keep running with screen off?

My app uses Handler and sendEmptyMessageDelayed to get timed messages that produce debug output. When I push power on my Galaxy Tab, the screen turns off but the debug messages keep coming.

I would rather that the CPU go to sleep. Is this happening because it's plugged in to the PC? Or could my app be doing something wrong that keeps the device awake?

Upvotes: 1

Views: 430

Answers (1)

Jason Robinson
Jason Robinson

Reputation: 31283

Turning the screen off doesn't put the phone into "sleep" mode, similarly to turning your computer monitor off won't put your computer into "sleep" mode. Mobile devices are designed to have quick responsiveness when you need them, thus never go to sleep unless explicitly told to (If such a function even exists).

In the context of an application, processing on the main (UI) thread decreases dramatically since UI elements are no longer being drawn to the screen. However, background processes still function as you would expect them to regardless of the screen state.

If you want your app to stop some processing when not in the foreground, check for calls to onPause() in your Activities, and do what you wish. onPause() will be called when changing Activities, turning the screen off, or moving the app into the background.

Upvotes: 2

Related Questions