1. Services service
A process that runs in the background for a long time, typically without an application interface
2. Relationship between process threads and applications
The application is turned on, the system starts a Linux process, and all the components are running in the same thread (main) of the same process.
(1) Process lifecycle life cycle
The Android operating system retains the application's process as long as possible, freeing up memory based on the process's priority recycling process.
If the process is reclaimed by the system, all open threads are gone.
(2)
Foreground Process Foreground processes
you can also see the interface of the application, and you can manipulate the application
Visible Process Visual processes
you can see the app, but it's not working.
Service Process Services processes
application with a service running in the background, the service does not stop
Background Process Daemon
the application is minimized, but does not exit
Empty Process
The application does not have any active components
Priority ordering:
Reception Process >
Visual Process
>
Service Process
>
Background Process
>
Empty Process
(3)
problem: If you turn on sub-threads, you can have no interface and run long-term. Why use a service instead of a child thread?
If you use a child thread (background process) to run the background, once the system discovers that there is not enough memory, it will release the memory according to the priority recycle process;
Services (
service process)
in the
the system found insufficient memory due to
The service process has a medium priority and is not first recycled, and even if the service process is recycled,
once the Android system finds enough memory, it will automatically restart the service process.
From for notes (Wiz)
Android (Java) Learning Note 225: Why services are used