Re: [android-developers] Poll Screen On/Off state

2009-11-03 Thread Mark Murphy
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 android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Poll Screen On/Off state

2009-11-03 Thread gudujarlson

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. The second part has me stumped. On
Windows Mobile I was able to poll the power state to determine user
idleness. On BlackBerry I was able to poll the device idle time.
However, there does not appear to be a way to determine user idleness
on Android.

Instead of polling for user idleness directly, I thought I might be
able to use the on/off state of the screen. There are 2 intents
ACTION_SCREEN_OFF and ACTION_SCREEN_ON and I was able to setup a
listener for these (BroadcastReceiver). The problem is that I do not
know how to determine the current state of the screen at the time I
register the listener, therefore I have to wait until the next screen
on/off change to know anything. The docs speak of some intents that
are sticky and thus will allow the current state to be determined,
but the screen events do not appear to have that property. What am I
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?




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