Services: Non-interface components running in the background
Android app: Where to use the service?
Weather forecast: The logic of the connection server in the background, get the latest weather information every once in a while
Stock Display: 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.
Purpose of the service:
1. Long-term background operation.
2. Improve the priority of the process, the system is not easy to reclaim the process, even if the recovery, memory is sufficient, the process of re-creation.
New Thread () {}.start (); The child thread does not have the interface, also is the long-term background to run, once the main thread ends, becomes the free process, cannot manage.
Android system process management is in accordance with certain rules:
1. Once the application is turned off, the process does not stop after it is normally closed (emptying the task stack). Next quick start.
A problem with insufficient memory.
The 2.Android system has a memory cleanup mechanism. Reclaims the system's memory by priority (from low to high).
The process is divided into 5 levels of priority: (High-to-low)
1.Foreground process the application that the foreground process user is playing
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.
4.Background Process Daemon application does not have service running and minimized (activity OnStop)
5.Empty process empty processes do not have any activity to run, the task stack is empty
A component that runs in the background for a long time and does not open a child thread in activity.
It should be to create a service and open a child thread inside the service.
Why Android uses the service