In addition to acquiring a partial wake-lock, try to make your service a 
foreground service.
This causes the service to be considered a foreground process and it shows 
the user a notification on the notification bar.
See the method Service#startForeground(int id, Notification not) in the 
api-docs for more info.

Be careful with this, though. Your app may consume more battery power than 
the user would care for.

On Wednesday, December 5, 2012 2:00:27 AM UTC-5, Archana wrote:
>
> Hi, I m doing it as part of a research project. I need my service to keep 
> running even when the device is asleep(until the user presses Stop button 
> in the App s GUI) and monitor difference in battery consumption. I used 
> PowerManager(implemented WiFi Locks also) because I read that CPU will be 
> ON during this period. When I plug device to the computer, it is working 
> fine. But as soon as it is disconnected, the service seem to stop. I want 
> to know if this is expected behavior? Please guide me in this regard.
>
> On Tuesday, December 4, 2012 9:08:02 PM UTC+2, G. Blake Meike wrote:
>>
>> You probably realize that just seizing a WakeLock for a long time is a 
>> really, really horrible idea, yes?  Given that, it isn't clear what you are 
>> actually trying to do.  Obviously, your service can't run when the device 
>> is asleep....
>>
>> You can use the Alarm Manager in 
>> RTC_WAKEUP<http://developer.android.com/reference/android/app/AlarmManager.html#RTC_WAKEUP>
>>  mode, 
>> to cause the device to be awakened, periodically, to run your service.  If 
>> you do that, you may have to seize a WakeLock to keep the device awake 
>> until your service has completed its task and is ready to let the device go 
>> back to sleep...
>>
>> G. Blake Meike
>> Marakana
>>
>> Programming Android 2ed is now in stores:
>> http://bit.ly/programmingandroid
>>
>

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