The first point is the lock screen function. You can refer to: https://github.com/chniccs/Lo... This small project is the implementation of the lock screen function, with a small amount of code.
Another point is to see how you define each operation. Here, an activity will be displayed in the foreground as an operation. You can also rewrite touch monitoring to define some touch operations as an operation. 1. Write a BaseActivity, send a delayed message (broadcast or other handler) in onResume (this is used here to represent an operation), and record the current time (stored in a custom Application or a global singleton or persistent storage ) 2. According to the previous method of sending delayed messages, such as broadcast, after receiving the broadcast message, compare the current time value with the time value recorded in step 1. If it is less than the defined time value, take it again The difference between the two time values (stored and current) is used as a delay before sending a broadcast. When the broadcast is received next time, it will be judged again. If it is greater than or equal to the time value, the lock screen will be called.
Explanation: Why do you need to take the difference value in step 2 instead of re-sending a fixed-delay broadcast? This is because after sending the broadcast for the first time, you may perform some operations, which will be subsequent operations, that is to say When you receive a delayed broadcast, the time of the last operation is not the time recorded when the broadcast was sent, but the time of the actual last operation. Therefore, the recorded time value needs to be updated after each operation.
Difference calculation: defined fixed maximum time of no operation - (current time - last operation time)
The first point is the lock screen function. You can refer to: https://github.com/chniccs/Lo...
This small project is the implementation of the lock screen function, with a small amount of code.
Another point is to see how you define each operation. Here, an activity will be displayed in the foreground as an operation. You can also rewrite touch monitoring to define some touch operations as an operation.
1. Write a BaseActivity, send a delayed message (broadcast or other handler) in onResume (this is used here to represent an operation), and record the current time (stored in a custom Application or a global singleton or persistent storage )
2. According to the previous method of sending delayed messages, such as broadcast, after receiving the broadcast message, compare the current time value with the time value recorded in step 1. If it is less than the defined time value, take it again The difference between the two time values (stored and current) is used as a delay before sending a broadcast. When the broadcast is received next time, it will be judged again. If it is greater than or equal to the time value, the lock screen will be called.
Explanation: Why do you need to take the difference value in step 2 instead of re-sending a fixed-delay broadcast? This is because after sending the broadcast for the first time, you may perform some operations, which will be subsequent operations, that is to say When you receive a delayed broadcast, the time of the last operation is not the time recorded when the broadcast was sent, but the time of the actual last operation. Therefore, the recorded time value needs to be updated after each operation.
Difference calculation: defined fixed maximum time of no operation - (current time - last operation time)
Adopt Handler’s postDelayed(Runnable, long) method
1. Define a Handler class
2. Start the timer
3.Stop the timer
That’s probably the number, you decide the time