When will an android stop its processor without blocking wakefulness?

I know that android uses tracking lock to support processor or screen. Obviously, the screen lock does not allow the active user timer to turn off the screen after a period of user inactivity.

But I wonder when exactly the cpu processor lock will happen.

1.If I create a new thread and continue to pump out the processor in the background without any lock, turn off the screen, this will not stop it. Will he stop and when will he stop?

2.As for the thread scheduled using Timer.schedule ()?

3.It leads to another question if I keep a long socket connection in a service that is blocked in socket.read (). Do I have to get a tracking lock to make sure that the service will wake up when the socket receives any form of data remotely?

Thanks.

+6
source share
2 answers

Answers to all your questions.

  • Android works when wake protection is active. No matter what processes and threads are running, it will still sleep. This means that if your thread or some other process did not activate trail blocking, your thread will not run and therefore will not drain the battery. A thread will be activated only when some other process acquires wakelock.

  • The same applies to Timer.schedule (). Let's say you write a timer that runs every second, but without some kind of wake lock, and they say that the android goes to sleep for 10 seconds. When he wakes up p at the 11th second, he will determine that your timer has expired 10 times, he will simply drop 9 instances and execute it only once. If you need very reliable timers, you will either have to get a tracking lock, or the AlarmTimer user.

  • Yes.

+5
source

What I learn from the various functions associated with Wake-Lock , the Android system will never sleep, if it is sleeping, you will not receive SMS, call i.e. Android will not run only an OS level task when it sleeps.
Wake-lock is a mechanism by which any application can request a system so that the device remains for it. An application can do work in the background, despite the fact that the user does not move to launch this application.

For 1 and 2, Akshar correctly explained. 3. With regard to performing any operations in your application, when the system is in a standby state (only the task of the OS level is being executed), you must first request a lock from the system, and then only the application can perform its operations. After completing the operations, you must release the tracking lock so that the system can proceed to managing tasks at the OS level.

0
source

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


All Articles