Android power management, sleep mode, etc.

It’s hard for me to understand the best power management practices and the state of sleep mode on an Android device.

  • Sleep mode.

    1.1) when will this happen?

    1.2) Will the CPU sleep, and are my threads suspended? and when will this happen?

    1.3) To prevent the processor from hibernating, can I use a lockout lock or PARTIAL_WAKE alarm manager? What is better for a battery?

    1.4) How to prevent software shutdown of Wi-Fi and 3G-connection in sleep mode from my application?

PS Yes, I understand that this is bad for battery life! I am trying to find the best compromise ...

  • I am writing my instant messenger application. I need a permanent connection to the server. What is the best way to achieve this? After ~ 20-30 minutes with the screen turned off, I lost my Internet connection, but Skype remains online. How do they do it?

  • I know about the structure of C2DM. But it is unidirectional from the server to the application. What is the best way to use it for me? The server must know that the client is really connected!

+2
source share
1 answer

when will this happen?

After the screen turns off, based on user settings for inaction.

Will the CPU sleep, and are my threads suspended?

Yes.

when will this happen?

You already asked about it.

To prevent the processor from hibernating, can I use a lockout lock or PARTIAL_WAKE alarm manager?

AlarmManager can cause the phone to AlarmManager up, but only very briefly. A WakeLock prevents the device from WakeLock sleep mode.

How to prevent software shutdown of Wi-Fi and 3G connection in sleep mode from my application?

Use WifiLock to prevent Wi-Fi radio from turning off. Radiotelephone communications are not affected by sleep mode.

What is the best way to achieve this?

If the user is not actively using the device, allow the connection to stop working. By definition, they do not participate in an instant messaging session if their device falls asleep.

I know about the C2DM platform

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

+5
source

Source: https://habr.com/ru/post/1495660/


All Articles