简体   繁体   English

在服务中获取WakeLock

[英]Acquire WakeLock in Service

I am making one android application where I am calling WebAPI in background in service. 我正在制作一个Android应用程序,在后台在服务中调用WebAPI。 So Do I need to acquire wake lock there to execute http request ?? 所以我需要在那里获取唤醒锁来执行http请求吗?

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. 第二种情况::在第二个WebAPI中,我需要上传照片/视频,然后需要在那里获取Wake Lock来执行此http。

Both http request are doing in Service . 这两个http请求都在Service

So Do I need to acquire wake lock there to execute http request ? 所以我需要在那里获取唤醒锁来执行http请求吗?

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 (eg, clicked on an action bar item)? 您是否根据用户刚刚做的事情(例如,单击操作栏项目)发出请求? Or are you making the request totally in the background (eg, in response to a GCM push message)? 还是您完全在后台发出请求(例如,响应GCM推送消息)?

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 . 想起来最简单的方法是:如果屏幕可能关闭或关闭 ,当你的HTTP请求是怎么回事,你可能需要一个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. 在第二个WebAPI中,我需要上传照片/视频,然后在那获取Wake Lock来执行此http。

This is identical to your first case, at least in terms of your decision and how to make it. 这与您的第一种情况相同,至少在您的决定以及如何做出决定方面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM