Android implementation principle description _ application intent task activity

Source: Internet
Author: User
Tags home screen

Task

In Android, a task is defined as a process in which multiple activities work together to complete an application. Note that the activity here does not need to belong to the same application. As shown in, the activity required by our task may come from multiple applications.

 

Activity can be seen as independent in the system and as the subject of a specific application, tasks associate some activities to implement a more complex function, one or more tasks can form an application. This is the relationship between the three. Simply put, an application contains one or more tasks, and a task contains one or more activities.

The following describes the basic principles of activity and task:

Most applications are started through the home screen shortcut (another method is to start through the system application launcher ). After an application is started, the root activity of the application is displayed in the current window, And the homepage activity is hidden in the background.

When we click the email icon on the home page, the List Message activity in the application is displayed in the current window, while the home activity is hidden in the background. Press the back key to return to the home page again.

Note that there is essentially a difference between the application back key and the Home Key Exit: Although both can leave the current activity, the back will destroy the status of the current activity, home Stores the status of the current activity.

About back:

The current activity will be terminated and returned to the previous activity (if the current activity is already a root activity, it will be directly returned to the home screen). In this process, the system will destroy the status information of the current activity. When we return to this activity again, the activity shown to us will be a brand new activity.

 

 

 

 

We can see that when we click the back button in the list messages activity, our list messages activity will be destroyed.

About home:

 

We can see that when we return home screen through the Home key, the List Message activity is not destroyed, but is called to the background. This means that when we jump to the activity again, we still see the original activity.

 

Of course, the above is only a majority of cases. There are special cases in the world, and Android is no exception.

Some activities from the background being "summoned" to foreground are still equivalent to re-creating a new instance, which is different from the results described by the front. Even if it is temporarily stored in the background mode (not destroied), its state data will be lost. For example, contacts and gallery. When you start the Contact application and click an entry to view details, what you see is not the detailed information of a specific entry that you opened previously, but the initial default Interface. This example shows that the State information of the current activity can not be saved in all cases after the return using the Home key.

The other is a special case related to the back key. When the front side mentions that most of the activities are returned to the home activity through the back key, the activity itself will be completely destroyed. By default, the method for the activity to respond to the back button is defined by destroy. However, in some special cases, developers can "Override" the corresponding back button event as needed to cancel the default destroy action. The music player is a typical application related to it. When a user triggers the back button in the player's root activity, the user switches to the background mode to continue playing the current music, and the home activity is converted to foreground.

To sum up, for developers, we can set some parameters to specify when a user clicks back or home during the development process, whether or not to destroy the current activity. We will discuss it in detail in later articles.

ActivityReuse:

In multiple applications, we can all use the same activity. At this time, a reuse problem is involved.

Example: contacts uses gallery to obtain image resources.

As we all know, contacts is the most common application on mobile phones. It is mainly used to store the contact information of the current user, which must contain the profile information of the contact. The image information on the Android platform is managed by gallery. Therefore, contacts must reuse the gallery activity to obtain the corresponding image information.

Applications developed for Android or other platforms must have a good sense of reusability, Which is required throughout the entire development process of the project. This includes how to use the existing resources of the current system, or considering that other applications may be used to meet specific requirements in the future. When the intent filter being called is not unique (if intentfilter is not unique, it indicates that the current activity is used in multiple places), a dialog box is displayed for users to choose from, this is indeed a perfect solution.

 

 

 

 

When we click the phone book in the home screen, the page will go to the list contacts activity. Then, we choose to view the phone information of a person. At this time, we will jump to the view contact activity, then we click Edit information and jump to the edit contact activity. When we select to add an image on the editing page, the list pictures activity in the gallery application is called to display the image stored on the mobile phone to the user. The user selects an image, then jump to the crop picture activity to edit the image size .......

Activity can be shared based on the fact that activities with the same intentfilter can be replaced with each other. In this case, the system will pop up a selection list for the user to select. The activity selected by the user will be loaded into the current thread to replace the original default activity.

Example of Running multiple tasks simultaneously:

:

 

We can see that in statue1, the user started the view map activity by clicking the map application shortcut in home screen; then the user clicked the Home Key to jump to state2, in state2, we can see that the view map activity is called to the background, and the current window displays the home screen; at this time, the user clicks the shortcut of the mcalendar application on the home screen to start the day view activity to enter state3; then we return to the home screen again, and click the map application icon to re-enter the view map activity, we can see that the current map is the same as the map we just used to exit with the Home Key. This is a typical example of Running multiple tasks at the same time. When we run an application, the other application is not destroyed, but is transferred to the background, waiting for the call to be accepted again, the current window is displayed.

There are two different ways to start an application:

Each app must provide at least one entry point for the user or the system to call the associated activities. The small icon in application launcher is the entry point of each individual app. In addition, the app can also start each other through activity as the entry point, and each activity contained in the app can be viewed as a potential entry point.

For example, in the phone call application, we can use the call program to directly dial the phone number; the other is to first find a phone number in the phone book and then associate it through the phone book activity, call the dialup program.

IntentAnalysis

Intent stands for intent. There are many explanations for this intent. Here I will talk about my personal understanding.

I remember that when I was in high school, I had to take a good class for a long time, and I felt thirsty from time to time. The result was very tragic: I didn't bring water, so I wanted to ask my friends to borrow a bottle of water to drink. However, they were far away from each other, and they were the course time. I couldn't make a lot of noise, so I wrote a note and threw it to my friends. Then I drank the water very well.

In this example, I want to drink water, which is one of my ideas, while my friends can provide me with water. But I can't do anything without thinking about water. I have to let my friends know that I want to drink water. At this time, the paper plays a key role. It records what I want to do and my intention. Therefore, the note that records my thoughts is an intent.

(We all know that our intention represents an idea in our daily understanding. It is an illusory thing. How is it equivalent to an entity such as a piece of paper. Here we can think that intent can be considered as the carrier of intent .)

The intent object contains two elements:

1) Action: for example, view, edit, call, and view image resources (I want to drink water on paper ").

2) data: Specific data provided for a certain behavior (information such as the information source written on paper, such as chenzheng_java ).

 

 

 

 

 

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.