Relationship Between Activity, service, task, process and thread

Source: Internet
Author: User

What is the relationship between activity, service, task, process and thread?

First, let's take a look at the definition of a task. Google defines a task as follows: a task is what the user experiences as an "Application. "It's a group of related activities, arranged in a stack. A task is a stack of activities, not a class or an element in the manifest file.
This means that a task is actually an activity stack, and an application that users usually feel is a task. From this definition, the task has no connection with the service or other components. It is only for the activity.

Service and activity are only two types of components provided by Android, in addition to content provider and broadcast receiver.

Generally, for an applicationProgramAll the components of is run in the main thread generated by the same process. However, we can also run different components in different processes. We can set the attributes of these components to run them in different processes. For example: <activity Android: process = "processa">. Of course, we can also set them to run in the same process, even if they are not in the same application (provided that these applications use the same Linux
User ID, and signed by the same organization ).

So what is the relationship between thread and these components?

Generally, we use a separate thread to run some long-time or high-computing operations to prevent similar operations from blocking process. For example, we can generate a thread for a service (such as a service for playing music), or a thread for methods. In short, when you don't want some operations to block main thread, create a thread!

What is the relationship between activity, service, task, process and thread?

First, let's take a look at the definition of a task. Google defines a task as follows: a task is what the user experiences as an "Application. "It's a group of related activities, arranged in a stack. A task is a stack of activities, not a class or an element in the manifest file.
This means that a task is actually an activity stack, and an application that users usually feel is a task. From this definition, the task has no connection with the service or other components. It is only for the activity.

Service and activity are only two types of components provided by Android, in addition to content provider and broadcast receiver.

Generally, all components of an application are run in the main thread generated by the same process. However, we can also run different components in different processes. We can set the attributes of these components to run them in different processes. For example: <activity Android: process = "processa">. Of course, we can also set them to run in the same process, even if they are not in the same application (provided that these applications use the same Linux
User ID, and signed by the same organization ).

So what is the relationship between thread and these components?

generally, we use a separate thread to run some operations that take a long time or a large amount of computing, to prevent similar operations from blocking process. For example, we can generate a thread for a service (such as a service for playing music), or a thread for methods. In short, when you don't want some operations to block main thread, create a thread!

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.