Android Overview Screen-Overview Interface

Source: Internet
Author: User

Android Overview Screen-Overview Interface
Android Overview Screen-Overview Interface

Link to the original article: http://developer.android.com/guide/components/recents.html#:target?#_blank "}

The Overview page (Overview Screen) is a system-level interface used to display recent accesses.Activity(Activities) OrTask(Tasks). You can scroll up or down to view the list, and select a task to restore or move it left or right to remove it from the overview page. SlaveAndroid5.0(API level is 21), including differentDocument(DocumentsMultiple instances of the same activity may appear on the overview page as multiple tasks. For example,Google DriveThis application assigns a "task" for each document it opens ". In this way, each document is displayed as a task on the overview page.

Vcq9s/pushed + pushed/pushed + 62r7XEPGNvZGU + pushed/LSxrP9s/pushed/ydLUsO/DpsH00dS + pushed/tbQPGNvZGU + pushed = "adding-tasks- to-the-overview-screen-Add a task to the Overview Screen "> Adding Tasks to the overview screen-Add a task to the Overview Screen

UseIntentClass flag to add a task. You can add more control over when and how a document is opened or re-opened on the overview page. And useYou can choose to use a new task or reuse an existing task when opening a document, the behavior defined in this configuration file will not change once defined.

 

Using the Intent flag to add a task-use the flag of the Intent class to add a task

When starting the activity, you shouldIntentPassActivityManager.AppTaskClassstartActivity()To create a document for your activity. If you want to create a logical breakpoint for the system to display your activity as a new task on the overview screen, you shouldFLAG_ACTIVITY_NEW_DOCUMENTThe flag is passed to start the activity.IntentObjectaddFlag()Method.

NOTE: FLAG_ACTIVITY_NEW_DOCUMENTThe flag bit has been replacedFLAG_ACTIVITY_CLEAR_WHEN_TASK_RESETThe latter has expired in Android5.0 (API level 21.

If you useFLAG_ACTIVITY_MULTIPLE_TASKThe system creates a task each time it opens the activity and adds the activity as the root activity. This operation allows the same document to be opened in multiple tasks. The following code demonstrates how to perform a main activity:

DocumentCentricActivity. java

public void createNewDocument(View view) {      boolean useMultipleTasks = mCheckbox.isChecked();      final Intent newDocumentIntent = newDocumentIntent();      if (useMultipleTasks) {          newDocumentIntent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);      }      startActivity(newDocumentIntent);  }  private Intent newDocumentIntent() {      final Intent newDocumentIntent = new Intent(this, NewDocumentActivity.class);      newDocumentIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);      newDocumentIntent.putExtra(KEY_EXTRA_NEW_DOCUMENT_COUNTER, incrementAndGet());      return newDocumentIntent;  }  private static int incrementAndGet() {      Log.d(TAG, incrementAndGet():  + mDocumentCounter);      return mDocumentCounter++;  }}

NOTE:QuiltFLAG_ACTIVITY_NEW_DOCUMENTIndicates the activity to be started. The startup method defined in the configuration file must be the default one:android:launchMode=standard

Used for main activitiesIntentWhen starting a new activity, the system will search for the existing task to find the first or second task, that is,IntentCurrentIntentComponent name and data. If no matching task is found, orIntentCarryFLAG_ACTIVITY_MULTIPLE_TASKFlag, a new task is created, and the upcoming activity serves as the root activity of the task. If the corresponding task is found, the system will bring the task back to the foreground andIntentTheonNewIntent()Method. Get this new activityIntentCreate a new document on the Start overview screen, as shown in the following code:

NewDocumentActivity. java

@Overrideprotected void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentView(R.layout.activity_new_document);    // TODO something}@Overrideprotected void onNewIntent(Intent intent) {    super.onNewIntent(intent);    /* If FLAG_ACTIVITY_MULTIPLE_TASK has not been used, this activity    is reused to create a new document.     */}
Using the activity attribute to add a task-use the attribute of the "activity" label in the inventory file to add a task

An activity can be defined in the inventory file as always starting to a new task, that is, using properties in the "activity" label:android:documentLaunchMode. When a user opens a document, this parameter has four types to produce different results:

IntoExisting

Activities reuse existing tasks. This parameter is similarIntentAddedFLAG_ACTIVITY_NEW_DOCUMENTFlag, but not addedFLAG_ACTIVITY_MULTIPLE_TASKYou can refer to the above Using the Intent flag to add a task-use the flag of the Intent class to add a description of a task.

Always

The activity creates a new task for this document, even if this document has been opened. This parameter is similarIntentAddedFLAG_ACTIVITY_NEW_DOCUMENTAndFLAG_ACTIVITY_MULTIPLE_TASKFlag.

None

The activity does not create a new task for this document. The overview screen treats this activity by default. level: the entire application is displayed as a task on the overview page, and the overview screen will wake up the last activity used by the user after the application is selected.

Never

The activity does not create a new task for this document. Different fromnone, Setting this parameter will overwriteIntentInFLAG_ACTIVITY_NEW_DOCUMENTAndFLAG_ACTIVITY_MULTIPLE_TASKFlag. Even if these flags are set, the entire application is displayed as a task on the overview page, and the overview screen will wake up the last activity you use after you select the application.

NOTE:When the parameter is not selectednoneAndneverThe activity must be defined:launchMode=standard. Ifandroid:documentLaunchModeIf the parameter is not definednoneThe parameter is used as the default value.

Removing Tasks-remove a task

By default, a task with a document is automatically removed from the overview page when its activity ends. However, you canActivityManager.AppTaskClass,IntentTo overwrite this behavior.

You can set the "activity" label attribute to exclude a task from the overview screen value, that isandroid:excludeFromRecents=true.

You can define the maximum number of tasks displayed on the overview page of your application, that isandroid:maxRecentsAttribute. This property is an integer and the default value is 16. When the maximum number of tasks is reached, the most recently used tasks will be removed from the overview page. The maximum value of this attribute is 50 (25 on low memory devices), and the minimum value is 1.

Using the AppTask class to remove tasks-Use AppTaskClass to remove a task

In the activity where a new task is created to the overview screen, you can define when to remove the task and callfinishAndRemoveTask()To end all activities associated with the task.

NewDocumentActivity. java

public void onRemoveFromRecents(View view) {    // The document is no longer needed; remove its task.    finishAndRemoveTask();}

NOTE:UsefinishAndRemoveTask()The method will overwriteFLAG_ACTIVITY_RETAIN_IN_RECENTSFlag.

Retaining finished tasks-keep completed tasks

If you want to display this task on the overview screen after the activity ends, you canIntentAddFLAG_ACTIVITY_RETAIN_IN_RECENTSFlag.

DocumentCentricActivity. java

private Intent newDocumentIntent() {    final Intent newDocumentIntent = new Intent(this, NewDocumentActivity.class);    newDocumentIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT |      android.content.Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS);    newDocumentIntent.putExtra(KEY_EXTRA_NEW_DOCUMENT_COUNTER, incrementAndGet());    return newDocumentIntent;}

To achieve the same effect, you can addandroid:autoRemoveFromRecents=false. The default value of this attribute isfalseThe default value istrueAnd this parameter will overwriteFLAG_ACTIVITY_RETAIN_IN_RECENTSFlag.

 

 

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.