android Power Management, Sleep mode, etc [closed]

主宰稳场 提交于 2020-01-01 19:00:57

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/14957645/android-power-management-sleep-mode-etc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!