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 -~----------~----~----~----~------~----~------~--~---