进入睡眠模式,当应用程序正在运行prevent移动 [英] prevent mobile from going into sleep mode when app is running
问题描述
我想prevent的Android手机进入睡眠模式时,我的线程发送HTTP请求。作为同时线程正在执行HTTP调用手机发生了什么事进入睡眠模式,当用户唤醒了电话线永远不会完成。
I want to prevent Android Mobile from going into sleep mode when my threads are sending HTTP request. as what happened while threads are doing HTTP calls mobiles goes to sleep mode and when user wakes up the phone threads never complete.
用户必须重新启动应用程序。该怎么办?请大家帮忙
User has to restart the app. what to do? please help
推荐答案
您需要 WakeLock 。有各种不同的唤醒锁,所以一定要选择最积极的一个能满足您的需求。尤其是,它听起来像你需要一个局部唤醒锁。
You need a WakeLock. There are different kinds of wake locks so be sure to select the least aggressive one that meets your needs. In particular it sounds like you need a Partial Wake Lock.
部分唤醒锁 - 唤醒锁,保证了CPU运行。屏幕可能不能上。
Partial Wake Lock - Wake lock that ensures that the CPU is running. The screen might not be on.
此外,还要确保你的权限 android.permission.WAKE_LOCK
添加到您的清单。最后是双务必<一个href="http://developer.android.com/reference/android/os/PowerManager.WakeLock.html#release%28%29">Release你的锁,当你做。
Also, make sure you add the permission android.permission.WAKE_LOCK
to your manifest. And finally be double sure to Release your lock when you are done.
这篇关于进入睡眠模式,当应用程序正在运行prevent移动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!