About Android services

Foreground process: You can see the application interface and interact with it. This is the foreground process!
Visual process: You can see this process, but it cannot be operated. This is also the difference from the foreground process, which is that it cannot be operated.
Service process: A process that is executed in the background for a long time and runs without an interface is called a service process.
Background process: The so-called background process is a program that is minimized and essentially does not exit.
Empty process: The components of the program do not have any activity, that is, they are hung up!


The size of memory is limited, that is, the size of the device is limited. The Android operating system needs to manage these resources reasonably, according to priority, to ensure that users can use them, etc. Therefore, these processes need to be prioritized. When resources are not enough, low-level processes will be killed or cleared.

Foreground process>Visual process>Service process>Background process>Empty process

Okay, when you see this, let's go back to the previous step and open a sub-thread to perform some tasks that will not exit without an interface. So let's do it like this: after starting a sub-thread, I directly minimize this program. Does it become a background process? Right, when the resources are not enough, it will kill the background process, and the child thread will never get up again!

However, the service is different. First of all, it has a higher priority than the background process, so it is not so easy to kill. In addition, the service is really killed because of insufficient resources. When the resources are released enough, or other things are executed, it is enough. Resources are available, and the service automatically starts running again!

Why do we use services?


The service can run in the background for a long time, even if there is no interface, its priority is relatively high and it is not easy to be killed.
Even if the service is killed, it can be automatically started by the operating system.

おすすめ

転載: blog.csdn.net/u011795345/article/details/104615852