Ne0 wrote: > Can you confirm if i am using WakeLock in the correct way please. > > //My Service > public void onCreate() { > ... > mPm = (PowerManager) getSystemService > (Context.POWER_SERVICE); > mWl = mPm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MGS"); > mWl.acquire(); > ... > } > > public void onDestroy() { > ... > mWl.release(); > ... > }
Assuming mWl is the same instance in onDestroy() as you got in onCreate(), that sure looks OK. You can test it by forking a thread to dump a message to LogCat every second and then SystemClock.sleep()-ing the rest of the second. If you get the LogCat messages, you know your service is still running. You can see a more elaborate example of WakeLocks and services in one of my book examples: http://commonsware.com/AdvAndroid/ (click the Source Code link, and look at SystemServices/Alarm) That is more simulating work coming in from multiple sources, including a boot-time-scheduled alarm, into an IntentService, and the IntentService having to do a bit of work to ensure it stays awake while there is work to do. > The intention is to keep the CPU going so my service can log when a > location change happens, works as i want while the phone is fully > awake, though even with the above WakeLock it stops logging the > changes. That may be a matter of the GPS radio turning off despite the WakeLock. Do you have any evidence that GPS is still on? I don't know much about that, except that keeping the GPS radio on means very short battery life. -- Mark Murphy (a Commons Guy) http://commonsware.com | http://twitter.com/commonsguy Android Development Wiki: http://wiki.andmob.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---