Service: A component with no interface running in the background for a long time
Where do I need services for Android apps?
Weather forecast: The logic of the connection server in the background, get the latest weather information every once in a while.
Stock Show: The logic of the connection server in the background, get the latest stock information every once in a while.
MP3 Player: Play music in the background for a long time.
---------------------------------------------------------------------------------
New Thread () {}.start (); A child thread has no interface and is running in the background for a long time. What is the difference from service?
The reasons are as follows:
Android system process management is in accordance with certain rules:
1. Once the application is opened, the process does not stop after it is normally closed (emptying the task stack).
Facilitates next quick start.
A problem with insufficient memory.
The 2.Android system has a memory cleanup mechanism. The memory of the system is recycled according to the priority level.
---------------------------------------------------------------------------------
The process is divided into 5 levels of priority: (High-to-low)
1.Foreground process The foreground process the user is playing the application corresponding to.
2.Visible process visual processes the user can still see the interface of this process.
The 3.Service Process Service application has a service component running in the background.
The 4.Background Process daemon application does not have services running and minimized (activity OnStop).
5.Empty process empty processes do not have any activity to run, the task stack is empty.
----------------------------------------------------------------------------------
Purpose of using service:
1. Long-term background operation.
2. Increase the priority of the process, the system is not easy to reclaim the process, even if the recovery, memory is sufficient, the process is automatically recreated.
Android Learning Note Service