You can't poll screen on/off state.  The best you can do is to
register a BroadcastReceiver, and wait for an Intent to come along.
Until that first Intent is received, you'll have no idea what the
screen state is.

On Nov 3, 6:28 pm, Mark Murphy <[email protected]> wrote:
> gudujarlson wrote:
> > I have an app that runs in the background indefinitely provided there
> > is work to be done. I want the app to go to sleep if there is no work
> > to be done and the user is idle.
>
> What does the user being idle have to do with anything here? If there is
> no work to be done, there is no work to be done, so stop your service
> and wake it up after some time to see if there is new work to be done.
>
> > What am I to do?
>
> Don't worry about "user idleness". Just stop your service and get it out
> of RAM when you have no work to do. Restart the service after a period
> of time, or based on some other event trigger, to see if there is new
> work to do.
>
> > In general, I find the lack of support for polling system state
> > properties (e.g. screen state, power state, signal strength) in
> > Android to be annoying. It's cool that one can listen for changes in
> > system state rather than constantly polling for them, but one still
> > needs to know the current state of the property at the time the
> > listener is registered. Am I missing something fundamental?
>
> Power is available on demand via a sticky Intent.
>
> WiFi signal strength is available on demand via WifiManager.
>
> GSM/CDMA signal strength is available on demand from TelephonyManager.
>
> --
> Mark Murphy (a Commons 
> Guy)http://commonsware.com|http://twitter.com/commonsguy
>
> Android Training in Germany, 18-22 January 2010:http://bignerdranch.com

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to