Search code examples
androidservicewakelock

Acquire WakeLock in Service


I am making one android application where I am calling WebAPI in background in service. So Do I need to acquire wake lock there to execute http request ??

Second case :: Here in second WebAPI where I need to upload photo/vidoes then do I need to acquire Wake Lock there to execute this http.

Both http request are doing in Service.


Solution

  • So Do I need to acquire wake lock there to execute http request ?

    That would depend upon a variety of factors, such as:

    • How long might the request take?

    • Are you making the request in response to something the user just did (e.g., clicked on an action bar item)? Or are you making the request totally in the background (e.g., in response to a GCM push message)?

    The simplest way to think of it is: if the screen might be off or turn off when your HTTP request is going on, you probably want a WakeLock.

    Here in second WebAPI where I need to upload photo/vidoes then do I need to acquire Wake Lock there to execute this http.

    This is identical to your first case, at least in terms of your decision and how to make it.