当将Android停止它的CPU没有唤醒锁? [英] When will android stop its cpu without wake lock?

查看:305
本文介绍了当将Android停止它的CPU没有唤醒锁?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道Android的使用唤醒锁,以保持CPU上运行或屏幕上。 很明显,屏幕唤醒锁定prevents从时间用户无操作后关闭屏幕的用户活跃定时器。

I know android use wake lock to keep cpu running or screen on. It's obvious that screen wake lock prevents the user active timer from turning off the screen after a period of user inactivity.

但我不知道究竟何时将CPU唤醒锁生效。

But I'm wondering when exactly will the cpu wake lock take effect.

1.如果我创建了一个新的线程,并保持排水CPU中的背景,任何唤醒锁,关闭屏幕也不会停止。它会停下来,什么时候才是个头?

1.If I create a new thread and keep draining cpu in background with out any wake lock, turn off the screen will not stop it. Will it stop and when will it stop?

2.关于计划与Timer.schedule()?线程

2.What about a thread scheduled with Timer.schedule()?

3.It引出另外一个问题,如果我继续在服务,这是挡在socket.read()长的套接字连接。我一定要获得唤醒锁,以确保该服务将被唤醒时套接字接收到任何数据形式的远程?

3.It leads to another question, if I keep a long socket connection in a service, which is blocked at socket.read(). Do I have to acquire a wake lock to make sure the service will be wakeup when the socket receives any data form remote?

感谢。

推荐答案

解答您所有的子问题

  1. Android的睡在没有唤醒锁是活动的。这不要紧,进程和线程运行它仍然会睡觉。这意味着,如果你的线程或其他进程那里还没有激活唤醒锁定您的线程将不会被执行,因此不会耗尽所有电池。只有当其他一些进程获取一个wakelock的线程将被激活。

  1. Android sleeps when no wake-lock is active. It does not matter what processes and threads are running it will still sleep. That means if your thread or some other process out there has not activated a wake lock your thread will not execute and hence will not drain any battery. The thread will be made active only when some other process acquires a wakelock.

同样适用于Timer.schedule()。假设你编写一个执行的每一秒,但没有任何唤醒锁定一个计时器,并说机器人进入睡眠状态,持续10秒。当它醒来P的11秒它会识别你的计时器已经过期10次便索性放弃九城实例并执行它只有一次。如果你想非常可靠的计时器,你将不得不要么得到一个唤醒锁或用户AlarmTimer。

Same is applicable to the Timer.schedule(). Say you write a Timer that executes every second but without any wake-lock, and say android goes to sleep for 10 seconds. When it wakes p on 11th second it will identify that your timer has expired 10 times it will simply discard the9 instances and execute it only once. If you want very reliable timers you will have to either obtain a wake lock or user AlarmTimer.

是的。

这篇关于当将Android停止它的CPU没有唤醒锁?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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