Why Android uses the service

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.