Android Learning Note Service

Source: Internet
Author: User

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

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.