Android的电源管理,睡眠模式等 [英] android Power Management, Sleep mode, etc

查看:114
本文介绍了Android的电源管理,睡眠模式等的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难理解电源管理的最佳实践和Android设备的睡眠模式状态。

  1. 睡眠模式。

    1.1)时,会出现这种情况?

    1.2)CPU是要睡觉,我的线程挂起?而当会出现这种情况?

    1.3)为prevent CPU睡觉,我可以使用PARTIAL_WAKE唤醒锁或报警经理吗?什么是最好的电池?

    1.4)如何WiFi和3G在睡眠编程模式下,从我的应用程序连接prevent关机?

PS是的,我明白,这是不好的电池寿命!我试图找到最佳平衡点...

  1. 我写我的即时通讯应用程序。我需要有服务器的持久连接。如何最好的方式来实现这一目标? 后〜20-30分钟与屏幕关闭我失去了互联网连接,但Skype的在线停留。他们是怎么做到的呢?

  2. 我知道C2DM框架。但它是从服务器向应用单向的。如何最好的方式来使用它给我吗?服务器必须知道客户真正连接!

解决方案
  

在会发生这种情况?

在屏幕关闭的基础上,为不活动的用户设置了一段时间之后。

  

CPU是要睡觉,我的线程挂起?

是的。

  

在会发生这种情况?

您问了。

  

要prevent CPU睡觉,我可以使用PARTIAL_WAKE唤醒锁或报警经理吗?

AlarmManager 能导致手机唤醒退出睡眠模式,但只有很简单。 A WakeLock $ P $进入睡眠模式摆在首位pvents设备。

  

如何WiFi和3G在睡眠编程模式下,从我的应用程序连接prevent关机?

使用一个 WifiLock 来prevent从关闭WiFi无线电。该电话的无线电不受休眠模式。

  

如何最好的方式实现这一目标?

如果用户没有主动使用设备,允许连接终止。根据定义,他们不参与IM会话,如果他们的设备睡着了。

  

我知道C2DM框架

此已取代GCM,其具有相同的基本特征。

I have difficulty in understanding power management best practices and sleep mode state of android device.

  1. Sleep mode.

    1.1) when will this happen?

    1.2) CPU is going to sleep and my threads are suspend? and when will this happen?

    1.3) To prevent CPU sleeping I can use PARTIAL_WAKE wake lock or alarm manager? What the best for battery?

    1.4) How prevent shutdown of WiFi and 3G connection in sleep mode programmatically from my app?

P.S Yes, I understand that it is bad for battery lifetime! I try to find best compromise...

  1. I write my instant messenger application. I need have persistent connection to server. How the best way to achieve this? After ~20-30 minute with screen off I lost internet connection but Skype stays online. How they do it?

  2. I know about C2DM framework. But it is unidirectional from server to application. How the best way to use it for me? Server must know that client really connected!

解决方案

when will this happen?

Sometime after the screen turns off, based on user settings for inactivity.

CPU is going to sleep and my threads are suspend?

Yes.

when will this happen?

You asked that already.

To prevent CPU sleeping I can use PARTIAL_WAKE wake lock or alarm manager?

AlarmManager can cause the phone to wake up out of sleep mode, but only very briefly. A WakeLock prevents the device from going into sleep mode in the first place.

How prevent shutdown of WiFi and 3G connection in sleep mode programmatically from my app?

Use a WifiLock to prevent the WiFi radio from shutting down. The telephony radio is unaffected by sleep mode.

How the best way to achieve this?

If the user is not actively using the device, allow the connection to terminate. By definition, they are not participating in the IM session if their device falls asleep.

I know about C2DM framework

This has been replaced by GCM, which has the same basic characteristics.

这篇关于Android的电源管理,睡眠模式等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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