Simple Explanation of tasks, processes, and threads in Android

Source: Internet
Author: User

I. Task

To explain what is a task in Android, You need to mention the application and Activity.

Activity: the most basic application component in Android. An Activity is usually a separate screen used to present data and interact with users.

Application: for example, QQ Software is an application, usually composed of multiple activities.

With the above two concepts, you can understand the task well. An Android task usually involves multiple activities, which may belong to different applications ).

From the Activity perspective, a task is the stack of the Activity.

 

Activity and task

The association between the Activity and the task, and the behavior of the Activity in the task are all set between a series of flags and a series of attributes of the <Activity> element of the Activity in the manifest file in the Intent object that starts the Activity. interaction control.

Intent flags:

FLAG_ACTIVITY_NEW_TASK

FLAG_ACTIVITY_CLEAR_TOP

FLAG_ACTIVITY_RESET_TASK_IF_NEEDED

FLAG_ACTIVITY_SINGLE_TOP

<Activity> attributes:

TaskAffinity

LaunchMode

AllowTaskReparenting

ClearTaskOnLaunch

AlwaysRetainTaskState

FinishOnTaskLaunch

 

Start the task:

When an Activity specifies an "android. intent. action. MAIN "as action," android. intent. category. when LAUNCHER is used as the intent filter of a category, it is set as the entry point of a task.

If you do not want the user to return an Activity again, set finishOnTaskLaunch to "true"

 

2. Android Process

The process where the component runs is controlled by the manifest file. Component elements such as <Activity>, <service>, <javaser>, and <provider> all have a process attribute to specify the process in which the component should run. <Application> the element also has a process attribute that sets the default process attribute values for all components.

 

3. Android thread

Android threads are created in the code using standard java thread objects. Android provides many classes to facilitate thread management: logoff is used to run a message loop in the thread, handler is used to process messages, and handlerthread is used to enable threads in a message loop.

 

In fact, there is no difference between android processes and threads and in linux.

Related Article

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.