Thanks for the reply Mark. I read from the docs that PARTIAL_WAKE_LOCK turns the screen off...but the CPU runs :(
Flag ValueCPUScreenKeyboardPARTIAL_WAKE_LOCK<http://developer.android.com/reference/android/os/PowerManager.html#PARTIAL_WAKE_LOCK> On*OffOffMy goal is..to shutdown some of my services when my application is idle, but keep only one service running (which is the main service of my application). Only when i start receiving packets from the underlying IP Connectivity Network and my protocol listeners intercept the messages,then i want to re-start these other services. If i do not take a wake lock, there is an outside chance that my Main service might be shutdown by android, which i want to avoid. So, you suggest, that i find an alternative to avoid a 'forever running' service to relieve the CPU ? That will be better to conserve battery life i suppose, as there will be no wake locks anymore to keep the CPU on. I will follow your suggestion then. It will be easy to find a workaround to avoid this long running service at this stage of my dev, as i have made just a proof of concept application right now to get my hands wet with all the concepts. Thanks for referring me the WiFiManager...i will take a look at it. ..and, thanks for taking the time to reply to my message. Its been of great help to me. On Thu, Sep 10, 2009 at 4:43 PM, Mark Murphy <mmur...@commonsware.com>wrote: > > Android Development wrote: > > 2. Now, if my application is idle (there is no incoming/outgoing > > traffic), i want to turn the screen off with the CPU still running by > > taking a PARTIAL_WAKE_LOCK. (Of course the user may switch to another > > application and turn on the screen in the process ! ) > > PARTIAL_WAKE_LOCK does not turn off the screen. The screen will turn off > on its own when there is nothing to keep the screen on. > > > (However the docs say that any Wake Lock is bad for the battery !! I > > thought that turning the screen off will save on battery ! ) > > The fact that you are trying to keep your code running all of the time > -- and hence keep the CPU running -- is bad for the battery. Allowing > the screen to turn off means it is somewhat less bad. It's like eating a > large greasy pizza by yourself, then having a Diet Coke. > > > 4. Now i will register a phone state listener like this: > > > > TelephonyManager tmgr = > > (TelephonyManager)context.getSystemService(context.TELEPHONY_SERVICE); > > AppPhoneStateListener myListner = new AppPhoneStateListener(); > > tmgr.listen(myListner, PhoneStateListener.LISTEN_DATA_ACTIVITY); > > > > // The docs say this data activity is for cellular. Does this mean i > > cannot get the state changes to WiFi data traffic ? (Eg: WiFi > > //connection idle..no traffic...incoming traffic starts etc) > > There are broadcast Intents for the WiFi state changes. Check out the > WifiManager class. > > > 5. After some time, i will receive a onDataActivity(int) > > < > http://developer.android.com/reference/android/telephony/PhoneStateListener.html#onDataActivity(int)> > callback > > when the data state changes. This is the time, i will initialize > > resources to handle the incoming traffic/ or send outbound traffic. Over > > here, i will also release the PARTIAL_WAKE_LOCK. > > What is your business goal? In other words, what are you really trying > to achieve with all of this convoluted code? > > > Or does it incur a considerable cost on the system battery/resources due > > to the PARTIAL_WAKE_LOCK ? > > As my lengthy post on this thread from yesterday attempted to > demonstrate, you will significantly reduce battery life by this > approach. You are keeping the CPU running 24x7, which is an > extraordinarily bad idea on a battery-powered device. You can easily cut > battery life in half, or perhaps worse in your case. > > Remember: just because something is technically possible does not mean > it is intrinsically efficient, or even practical. > > -- > Mark Murphy (a Commons Guy) > http://commonsware.com | http://twitter.com/commonsguy > > Need Android talent? Ask on HADO! http://wiki.andmob.org/hado > > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---