Design ideas and methods for activity and task

Source: Internet
Author: User
Tags home screen

Original article addressHttp://developer.android.com/guide/practices/ui_guidelines/icon_design.html

Activity and task are android
Application
The most basic applications in the framework architecture, developers must understand their usage and some development skills. This article provides a step-by-step in-depth and comprehensive explanation of their basic principles through reference of instances.
(Underlying)
Principles) and Schema (such as: navigation, multitasking, Activity
Re-use, intents, and activity
Stack... Most of its application modules. Focuses on how to more accurately reflect the convenience and efficiency of user interaction in the development process, and also helps analyze
Problems faced by developers during development.

Some of the instances involved in this article belong to the platform's own
Application (for example, dialingProgramIn addition, there are some representative applications in the Google product line (for example, Google
Map ). We recommend that you use emulator or Android-powered
Device to test the effect of the Instance. This helps you better understand the meaning of some modules. (Note: Some instances may be unable to provide support for certain functions due to hardware failure.
Your test machine can be viewed normally)

First, you need to understand some basic modules:
    • Applications
    • Acitivities
    • Activity Stack
    • Tasks

The above four modules understand this articleArticleIt is very important to briefly describe the specific meaning and usage (you can also directly view the official documentation through its link ).

Applications

Any Android Application is basically composed of some activities
When a user interacts with an application, some of the activities it contains have close logical relationships, or each of them processes different responses independently. These activities are bundled together
For an application that handles specific requirements,
In addition, the extension named "pai.apk" is stored in the file system. Android applications by default, such as email, calendar, browser, maps,
Text message, contacts, camera, and dialer are independent apps.

Activities

As mentioned above, activities are components.
The main component of applications, in fact, can be more specifically understood as the application is only an abstract label, it will be a part of the system activities
And collaborate to fulfill specific user needs. Install
The application process can also be understood as importing the wrapped activities to the current system. If the same activities already exists in the system,
The same activities will be automatically associated without repeated installation to avoid resource waste. When the application is uninstalled, the associated
Whether activities are associated with other application labels. If you only provide the current application, activities will be completely removed. Otherwise, activities will not be associated.
Any operation.

Most of the interactions between users and applications are
The GUI can be used to define the GUI in two ways on the Android platform. XML can be used to preset static GUI elements or to dynamically define the GUI within the activity class.
Gui element. The two methods are composed
Activity is the main body driving and responding to user interaction events. After the application is started, at least one activity instance containing GUI information must be created.

The activity body consists of two main parts: content (data) and response to user interaction events. List a dialer example, which includes four parts: The Dialer main interface, Address Book, viewing contact information, and adding new contacts.

The following lists more representative applications and their activities:

    • Email-activities to view folders, View list of messages, view a message, compose a message, and set up an account
    • Calendar-activities to view day, view week, view month, view agenda, edit an event, Edit Preferences, and view an alert
    • Camera-activities for running the camera, viewing the list
      Pictures, viewing a picture, cropping a picture, running the camcorder,
      Viewing the list of movies, and viewing a movie
    • Game-one activity to play the game, typically another for setup
    • Maps-one activity to view a location on a map, a second for lists
      (Such as turn list or friend list), and a third for details (friend
      Location, status, photo)

The application is basically composed of four modules: Activity, service, content provider, and broadcast receiver. activity is the main body of the application.

Activity Stack

When operating an application, you sometimes need to call multiple
Activities to fulfill the requirements. For example, to send an email program, first enter the main interface of the email, and then start a new activity to fill in the content of the new email, and call up the contact
The list is used to insert Recipient Information. During this operation
The Android platform has a mechanism dedicated to managing activities stacks. It can easily record activities instances linearly. When an operation is completed
The navigation function returns the previous activity (by "back" of the console ").

Each time a new activity is started, it will be added
Activity stack. You can easily return the previous activity until the home screen arrives at home.
After screen, you cannot view the stack record again (as the saying goes:-androidres.com ). If the current task is aborted (interrupting
The task), and other operations are started after the system main interface is returned. If you want to return to the previous Task for further execution, you only need to go through the application
Launcher or the shortcut to start the root activity of the task can return the status of the task to continue execution.

Compared with views, windows, menus, and
In terms of dialogs, Activity is the only one that can be recorded in history
The data in the stack, so when the application you designed requires the user to enter the next-level interface B from interface A, and the user needs to return a again after the operation is completed, you must consider a
Activity. Otherwise, it cannot be returned from the history stack.

Tasks

On the Android platform, tasks can be simply understood
Multiple activities work together to complete an application, regardless of the specific activities
Application. The following figure shows the relationships among applications, tasks, and activities.(Provided by androidres.com):

Activities can be viewed as independent systems resources and as the subject for implementing specific applications. Tasks associate activities to implement a more complex application, A single task or multiple tasks can be defined as an application.

Generally, a task has a root user.
Activity, but not in all cases, through the application launcher, home screen shortcut or
"Recent
Tasks "(hold down the home key for a long time) is started in recently used task records. When you start another activity from one activity, the back key acts on
Returns the previous activity, and the newly opened activity is added to the activity stack.

Here are two examples represented as tasks:

    • Send emails with attachments
    • View YouTube videos and share them with other contacts by email.

-Interrupting the task

This is a very important feature of tasks. Users can abort tasks in real time.
For a task that is not completed yet, start a different task. After the new task completes the operation, you can still return the task that is terminated once to continue the remaining operations. This feature greatly facilitates the same
Run multiple tasks and switch between them conveniently. There are two ways to jump from the current task to another task (the application of the two ways to switch the task, are allowed to return
The status before the task is terminated ).

    • The system throws a notification. The current task is terminated and jumps to the notification task.
    • User force stop

Of course, in addition to the two methods, there is another special case,
The third method is to start a new task: the activity itself is defined as a task. For example:
Maps and browser are application in the third case. You can use an address in the email to start maps.
Activity as a new task, or start browser through the link in the mail to start a new task. In this case, when the back button is triggered
Return to the previous task because these new tasks are not passed through the application in the home screen
Launcher or quick start.

Understand the basic principles of activities and tasks

Please first understand the content mentioned above. If you are still confused about some concepts, please read more information in time (the official document is the best learning material ), otherwise, you will not be able to quickly understand the examples to be discussed next, or even lose your interest in reading.

Next, we will learn the basic principles of applications, activities, activities stack, tasks, intent, and other modules through some representative instances. Analyze the system's response principles to users in different modes from various perspectives. 

Start an activity from home

Most applications are started from this (there are also
Some applications are started through other applications ). There are two specific methods:
Launcher is started, and the other is a shortcut directly by home screen. After the application is started, Root
The activity is displayed in the current window and can be directly used to operate interface elements. The official website provides an illustration of this process. In fact, I feel that this description is not intuitive enough to use it together. General
The process is to start the email application at home. In this application, list messages can be directly provided to users.
Activity and home activity switch to the background for running.

The difference between leaving the current activity using the back or home key

Both the application back and home can leave the current activity (Application-based root activity), and the home activity switches back to foreground. However, the most fundamental difference between the two is whether the user needs to retain the state of the current activity.

-Back:

Destroy
Activity, returned to the previous activity (if it is a root activity, it will be directly returned to home
Activity ). An official diagram of the related process is provided. When a user is operating the list messages
Activity, drop-down email list (changed the scrolling status), return to home activity through the back key, when again through email
Icon to start list messages
Activity, the list is in the initial position. Through this demonstration, we can understand that when the current activity is left by the back key, its state data cannot be temporarily retained. When
Restarting an instance is equivalent to re-creating an instance.

-Home:

Use home to replace the method returned by back.
Activity will be switched to background instead of destroied. In this way, the state information of the activity can be retained temporarily.
Use Application
When launcher or shortcut is started, it can return to the final exit status. Compare the example referenced in back. When the returned result is returned from home to activity again, the final result is displayed.
The status of the scroll recorded by an operation, rather than the default initial position.

Exception)

The front side lists two typical cases, and there are some exceptions.
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 in the front. Even
Is temporarily saved in background mode (not destroied), and its State data will also be lost. Example: contacts and gallery
. When the user starts the Contact application and clicks an entry to view details, if the returned result is returned by the Home Key and starts the Contact application again, what is not
The detailed information of a specific entry that was previously opened, but the initial default Interface. This example shows that the State information of the current activity can be saved in not all cases after the return using the Home key.
.

The other is a special case related to the back key. Mentioned above
Most of the activities return to home 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
To "Override" the corresponding back button event as needed, and cancel the default destroy action. Music player is a typical application related to it.
After the back button is triggered in the Root Activity
Convert activity to foreground.

Activity Reuse

In multiple different applications
For applications of the same purpose, the reusability of the activity is involved, which is very common in the development process. Reusability has been emphasized by many development institutions to save costs and optimize resources
Effective Mechanism. For the mobile application platform, the optimal utilization of resources is more important, and reusable applications are everywhere on the Android platform. Two basic examples are provided to illustrate the situation.

-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.

For Android or other platforms
To have a good sense of reusability, this needs to run through 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
When the intent filter being called is not unique, a dialog box is displayed for users to choose. This is indeed a perfect solution.

-Extended gallery sharing using messaging

You can use gallery to view image resources in the current system,
You can use menu->
Share inserts the current resource into the newly created messaging as an attachment and shares it with the recipient as a normal message. If you cancel the current sharing behavior, you only need
The back button is returned to the gallery activity. The difference from the previous example is that the message
If the activity is sent or canceled, no information is returned.

The above two examples illustrate how to use a series of activities to fulfill a certain requirement, and both of them call external application resources.

Replacing an activity

Currently, we want to introduce activities with the same intent filter attribute in different applications, which is not easy to understand for users who are used to operating systems such as Windows. In fact, if you are careful enough, you can find the information mentioned here in the previous example.

This usually occurs because the external
Function activity A is superior to the default action activity in the current application in terms of problem handling capability.
B. The system will throw a dialog box for users to select the optimal way to process the current task based on subjective judgment. We recommend that you use an instance that is easy to understand to describe the entire process.
You can try it on the simulator.

For example, the user loads the latest phone in the current system
Ringtone activity, named rings extended. If you use setting->
Sounds & Display-> phone ringtone
Ringtone activity and newly loaded rings
Extended provides two optional operation applications. In the dialog box, you can also provide a default operation option that allows you to directly start the system. If you select rings
Extended, it will be loaded into the current thread to replace the original default operation behavior, you can enhance understanding according to the following illustration.

Multi-task concurrent running (multitasking)

In the previous sections, we mentioned home and back.
Switch to home
Screen methods and their differences. This chapter will focus on how the system can process multiple real-time tasks at the same time. If the user is in an application
When a is enabled, the previous application is retained when the home activity is switched back through the Home button.
The status information of a running. You can enable the new program and switch application a back to foreground.

Next, we will learn more about the process covered by map application through an instance.

The initial phase consists of three steps,

Step 1: Start the map application by application launcher and search for a specific geographic location. Assuming that the current network environment is not ideal, it takes some time to download map data.

Step 2: when the system needs to load the current map information data for a long time, keep the current activity status, return home activity to start other applicaton, and switch the map activity to background, the loading progress is not interrupted (the network connection is still maintained ).

Note: The above is the response behavior of the activity under the default conditions. After switching to the background status, the onstop () event is directly triggered. developers can redefine the method. For example, force the activity to terminate the network connection in the background state.

Step 3: The current map activity has been switched to the background state and the home activity has been switched to foreground. At this time, the user starts the calender activity, which will be automatically converted to the foreground status, and get the operation focus.

The preceding three steps are illustrated as follows:

Finally, exit the current calender activity and return to home. Use the maps icon again to switch the instance in the background status to foreground.

The preceding example shows that the system has a multi-task processing mechanism-running multiple tasks.

Two different ways to start Application

Each app must provide at least one entry
Point (translated as an "entry point" is a bit awkward, simply keep it as it is) for the user or the system to call the associated activities, Application
The small icon in launcher is the entry point of each independent app. In addition, apps can use activity as an entry between them.
Point to start, you can view every activity contained in the app as a potential entry point.

PHONE IN THE SYSTEM
Application also has two entry points: contacts and dialer. As shown in the following figure, you can see that the Application
Launcher starts the contacts activity, selects a contact, and calls the dialer activity to call the provided phone number.

Intents

In the real world, everyone will interact with the surrounding environment every moment.
The interaction process first needs to determine a kind of consciousness, for example, feeling thirsty and needing water to supplement. This kind of consciousness will guide you to solve the thirst problem in the way you are used to. There are many ways to use it.
Ice cream, drinking water, chewing leaves, etc. Similar to thirsty ideology, which is abstracted as intent and viewed as an object, Android responds to consciousness.

On the Android platform
The same event composition, the system abstracts every event
Intent object to find a specific solution to this requirement. The abstract intent object has two forms. The first is the explicit intent (explicit
Intent), a specific activity has been associated for this intent during initialization. The second type is the "ambiguous" intent (implicit
Intent) indicates that the intent is not explicitly associated with the activity. When it is thrown, the system
Filter to find the matching processing method. If multiple results exist, you can select an appropriate processing method as needed.

Referencing a specific example, after clicking a mailto: info@androidres.com link, the thrown intent belongs to the implicit intent, and the system captures the result for resolving this intent, select all the results (Gmail or email ):

The following shows the default intent Association list for more systems:

    • View the list of contacts-resolves to a contact list viewer Activity
    • View A participant contact-resolves to a contact viewer Activity
    • Edit a particle contact-resolves to a contact editor Activity
    • Send to a special email-resolves to an email Activity
    • Dial a phone number-resolves to A Phone Dialer Activity
    • View the list of images-resolves to an image list viewer Activity
    • View a particle image-resolves to an image Viewer Activity
    • Crop a particle image-resolves to an image Cropper Activity

The intent object contains two elements:

1) Action: such as viewing, editing, dialing, and viewing image resources.

2) data: Specific data provided for a certain behavior. Fruit must be provided for juice beverage processing (excluding the black heart store ).

Refer to the official website for explanation: intent class and intent filters.

Task Switching

The switching process is still explained by the application instance. In this example, the user edits a short message and inserts an image attachment, but starts the calendar before sending the message, switches back to the short message editing page, and finally sends the message.

1) start the first task: messaging
APP, Home> messaging> new message> menu> attach>
Picture. To insert an image, you need to call gallery activity, which is an independent external program.

Next, start another task. Because calendar is not directly run from the current activity, you need to switch to home.

2) start another application (calendar): Home> calendar

3) after viewing the calendar, switch messaging from background to foreground mode, including adding attachments and finally sending messages.

 

At this point, two core elements of the Android platform are compared:
Activities and tasks
The introduction has come to an end. You may have more discussions in this area in the future. In addition, some friends may have read the official original text, and this site is lucky to have your own reading, such
If there are omissions or misunderstandings in some concepts or discussions, we sincerely hope to get correction and help.

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.