Android (Java) Learning Note 225: Why services are used

Source: Internet
Author: User

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

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.