PARTIAL_WAKE_LOCK VS SCREEN_DIM_WAKE_LOCK在下载线程 [英] PARTIAL_WAKE_LOCK vs SCREEN_DIM_WAKE_LOCK in download thread

查看:413
本文介绍了PARTIAL_WAKE_LOCK VS SCREEN_DIM_WAKE_LOCK在下载线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个生成一个下载线程下载有时大文件的服务。我意识到,只要手机去睡觉,下载线程将显著减速,然后停止。

I have a service that spawns a download thread that downloads sometimes large files. I realized that as soon as the phone went to sleep, the download thread would slow down significantly, then stop.

最明显的补救办法,一个wakelock。所以,我认为这将是确定收购partial_wake_lock,只是为了保持CPU处理的下载。这并不工作,但,同样的行为,在下载减慢,然后停止,当屏幕关闭。

The obvious remedy, a wakelock. So I would think that it would be ok to acquire a partial_wake_lock, just to keep the cpu processing the download. That doesn't work though, same behavior, the download slows and then stops when the screen turns off.

然后我尝试了screen_dim_wake_lock。这个时候,屏幕上停留(灰色),并下载继续前进,在全速,直到它被完成,wakelock释放,然后电话睡着了。

Then I tried a screen_dim_wake_lock. This time, screen stayed on (dimmed), and the download kept going at fullspeed until it was done, wakelock released, and then phone slept.

我的问题是,为什么我不能让我的线程中运行持相同的,因为它一screen_dim_wake_lock期间做了partial_wake_lock什么时候?有没有关于这两个之间的区别一些无证行为?是不是因为我不是在UI线程上运行的吧?

My question is, why can't I keep my thread running when holding a partial_wake_lock the same as it does during a screen_dim_wake_lock? Is there some undocumented behavior about the difference between these 2? Is it because I am not running on the UI thread perhaps?

编辑:

我添加了一个wifilock。支持WiFi不进入睡眠状态,但我的线程仍然死亡。如果一些其他过程唤醒系统,下载将继续正常速度,然后慢下来了。如果我醒来的手机,它将继续以正常速度时,屏幕熄灭比将有所放缓一次。却仿佛该线程得到推到背景由系统。我不知道如果我能prevent了。

I added a wifilock. The wifi doesn't go to sleep, but my thread still dies. If some other process wakes up the system, the download will continue at normal speed, then slow down again. If I wake up the phone, it will continue at normal speed than will slow down once again when the screen goes out. It seems as though the thread is getting pushed into the background by the system. I wonder if I can prevent that.

推荐答案

我有一个服务同样的问题,你不断地下​​载大集 的网址。最好的方法是使用一个screen_dim_wake_lock像你一样,把你的服务, 前景,如上所述<一个href="http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/ForegroundService.html"相对=nofollow>这里。

I had the same problem with you with one service that continuously download a large set of URLs. The best way was to use a screen_dim_wake_lock as you did and bring your service to the foreground, as described here.

在这样的画面总是在的,所以同样的情况,并与你的Wi-Fi接口。在相反,如果你留下电话不活动了一会儿,然后屏幕会关闭,手机会进入睡眠模式,WIFI将关闭过,15分钟后!

In such a way the screen is always on, so the same happens and with your WI-FI interface. In contrary, if you leave the phone inactive for a while then the screen will turn off, the phone will get in sleep mode and the WIFI will turn off too, after 15 minutes!

那么,另一种方法是使用partial_wake_lock(仅CPU上),并改变手机的设置,以便为WIFI要始终打开(也许这好像你获取WIFI_LOCK ..):

So, another way is to use a partial_wake_lock (only CPU is on) and change the settings of your phone so as the WIFI to be always on (maybe this seems like the WIFI_LOCK you acquires..):

  • 从主屏幕进入系统或设置,然后
  • 选择无线与网络
  • 选择Wi-Fi设置
  • preSS菜单,选择高级
  • preSS的Wi-Fi休眠策略,并将其更改为从不
  • from home screen go to System or Settings and then
  • select Wireless & Networks
  • select WI-FI settings
  • press Menu and choose Advanced
  • press Wi-Fi Sleep Policy and change it to Never

那么你的服务将工作,即使在睡眠模式下屏幕关闭。这里唯一的问题是:

Then your service will work even in sleep mode with the screen turned off. The only problem here is:

如果你失去WiFi连接了一会儿,然后在Android可能会杀了你的服务,因为这将是不活动的。但是,如果你的手机总是连接到WiFi网络具有良好的稳定性,然后一切都将正常工作!

if you loose WIFI connectivity for a while then the Android may kill your service because it will be inactive.. But if your phone is always connected to the WIFI network with good stability then all will work fine!

这篇关于PARTIAL_WAKE_LOCK VS SCREEN_DIM_WAKE_LOCK在下载线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆