What is the knowledge of the official API. However, since many people are not good at English, they have reproduced this article, and the translation is very good. Do not understand the Activity declaration cycle, and the program framework design, it is best to take a look.
Activity and task Design Abstract
Activity is the main component of Android applications.
In addition to writing the Activity by yourself, you can also use intent to easily reuse the Activity of other applications.
You can enable the Activity in your application to be used by other applications through intent.
The system's Activity stack can handle almost all the situations. However, in either case, you may need to set the flag or the like to determine the right thing happens.
In this document
Applications, Activity, Activity stack, and Task
An example of Activity and Task
Start an Activity from the main screen
Leave an Activity
Reuse an Activity
Replace Activity
Multiple tasks
Start the application from two entry points
Intent
Switch between tasks
Design Recommendations
If you do not want your Activity to be reused, do not use intent filter.
Note that the intent cannot find the activity.
How to start the application
Allow the Activity to be added to the current Task.
Notification should make it easy for your users to leave
Use Notification system
Do not control the BACK key unless absolutely necessary.
Reference
Application Basics
This document describes the core principles of the Android Application Framework from a high-level, user-centric perspective. This is useful for interaction and Application designers and application developers.
This article uses multiple examples to illustrate the Activity and Task, and describes some of their underlying principles and mechanisms, such as navigation, multi-Task, Activity reuse, Intent, and Activity stack. The document also highlights some design conclusions you can use and how you control the UI of your application.
This document uses many Android applications as examples, including some default applications, such as Dialer and Google applications, such as Maps. You can try them on your Android simulator or Android phone. Note that your mobile phone may only provide some examples and applications in these documents.
Some principles, suggestions, and precautions will be mentioned in the design recommendations section. The basic Application covers the underlying mechanism of the program. This document supplements and improves it.
Applications, Activity, Activity stack, and Task
The following four basic concepts help you understand:
Application
Activitie
Activity Stack
Task
Application
A typical Android Application is composed of one or more related loosely coupled activities that users can interact. Typically, an Application is packaged into a separate apk file. Android apps with a large ticket may include emails, calendars, browsers, maps, text messages, contacts, photos, dialing, playing music, setting, and so on.
The Android main screen is generally the app starter. In general, it is a sliding drawer with many application icons (that is, under the default Android system, there will be a lot of icons when you drag your fingers up .), You can start the application from above.
Activity
Activity is the main component of Android applications. When you create an Apllication, you can create your own Activity or reuse another Application Activity to assemble the Application. These activities are bound together at runtime, so newly installed applications can benefit from the installed Activity. Once combined, these acitifiers work together as a whole. An Activity has an independent visual UI, which should be based on an independent and clearly defined intent. For example, other user behaviors such as viewing images, editing, dialing, taking photos, searching, sending data, and voice commands. An Application that needs to be displayed on the interface must have at least one Activity.
When an Android device is used, the user will jump from one interface to another, which should be smooth. Users should not be aware of underlying behaviors, such as switching between activities or tasks.
An Activity holds a specific type of content (data) and receives a series of related user actions. In general, the lifecycle of each Activity is irrelevant to other activities in the same Application or Task. Each Activity is run independently. You or the system can start, run, pause, resume, stop, or restart the Activity as needed. Due to this independent feature, there are many ways to override or reuse the Activity.
The dialing program provided by Android is an example of an Activity combination. This program is composed of four activities: Dialing, contact list, contact details, and creating a contact. As follows:
Below are some examples of other applications composed of multiple activities:
Email-view the directory, view the message list, view the message, write the message, and configure the account.
Calendar-view the day, week, month, and plan, edit the time, set attributes, and remind
Camera photography-run the camera, view the image list, view the image, cut the image, run the camera, watch the video list, and watch the video
Games-games themselves and installation settings
Map-view the current location, list (turn list or friend list), details (friend location, status, photo)
Activity is the most important of the four components that constitute the Application. The other components are Service, ContentProvider, and BroadcaseReceiver.