Android 5.0 Overview Screen -- Overview Screen, androidscreen --
Overview screen-overview screen, usually refers to the latest screen, latest task table, or the latest app. It is a system-level UI that displays the recently used activitys and tasks. You can use it for application navigation, or select a task for resume. Of course, you can also remove a task or activity from the list.
In Android L, an activity contains multiple events. Therefore, an Activity contains multiple files (documents) in the overview screen as tasks.
For example, multiple documents in Google Drive form a task and are displayed in overview screen.
Generally, you should allow the system to determine how your tasks and activities are displayed in the overview screen, and you should not modify such behaviors.
However, your app can determine when and how to appear in overview scree. The ActivityManager. AppTask class allows you to manage tasks by yourself. Of course, you can also use the flag label of the Intent class in the manifest file to describe when an activity is added and removed from the overview scren.
Add a Task to Overview Screen
You can use the Flag label of the Intent class to add tasks to the overview screen to provide greater control over opening or re-opening a document in the overview screen.
When you use attributes, you can choose to always open a document in a new task or reuse an existing task for the document.
Use Intent flag to add a task
When you call the startActivity () method in the ActivityManager. AppTask class, the current activity creates a new document and passes an Intent to the document. If you add the addFlags () method to Intent and pass the flag: FLAG_ACTIVITY_NEW_DOCUMENT method, the system displays the created Activity as a new task in overview screen.
Note: The FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET label has been deprecated in Android 5.0 and replaced with FLAG_ACTIVITY_NEW_DOCUMENT.
When you create a new document, if the FLAG_ACTIVITY_MULTIPLE_TASK label is added to the Intent, the system will create a new task forever, set the target Activity as the root of the task, so that the same document can be opened in multiple tasks.
The specific example is as follows:
<span style="font-family:Microsoft YaHei;font-size:14px;">public void createNewDocument(View view) { final Intent newDocumentIntent = newDocumentIntent(); if (useMultipleTasks) { newDocumentIntent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK); } startActivity(newDocumentIntent); } private Intent newDocumentIntent() { boolean useMultipleTasks = mCheckbox.isChecked(); 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++; }}</span>
Note: If the FLAG_ACTIVITY_NEW_DOCUMENT label is set for the started Activity, it must be set to android: launchMode = "standard" in the mainfest file"
When the main activity starts a new activity, the system will search for the Intent action name and Intent data in the current task to match the Intent passed by the main activity. For details about how Intent is parsed, refer to the blog Android Intent Filter analysis.
If no matching task is found, or the Intent of the main activity contains the FLAG_ACTIVITY_MULTIPLE_TASK tag, the system creates a new task and uses the activity as the root activity.
If the system finds a matched task, the task is placed on the top of the stack and an Intent is passed, the new activity obtains the Intent and creates a new document in overview screen.
Example:
<span style="font-family:Microsoft YaHei;font-size:14px;">@Overrideprotected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_new_document); mDocumentCount = getIntent() .getIntExtra(DocumentCentricActivity.KEY_EXTRA_NEW_DOCUMENT_COUNTER, 0); mDocumentCounterTextView = (TextView) findViewById( R.id.hello_new_document_text_view); setDocumentCounterText(R.string.hello_new_document_counter);}@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. */ setDocumentCounterText(R.string.reusing_document_counter);}</span>
Add a task using the activit attribute
When an activity is added with the attribute android: documentLaunchMode in the mainfest file, a new task will always be created when the activity is started. This attribute has four values, which have different effects when you open a document in the application:
Exist existing: activity will request an existing task for this document, which has the same effect as setting FLAG_ACTIVITY_NEW_DOCUMENT and not setting FLAG_ACTIVITY_MULTIPLE_TASK.
Always: activity will create a new task for the document, even if the document has been opened, which has the same effect as setting FLAG_ACTIVITY_NEW_DOCUMENT and setting FLAG_ACTIVITY_MULTIPLE_TASK.
None: The activity does not create a new task for the document. This app is set to the single task mode. It will re-call the most recent one of all the activities that the user wakes up.
Never: The activity does not create a new task for the document. The FLAG_ACTIVITY_NEW_DOCUMENT and FLAG_ACTIVITY_MULTIPLE_TASK labels are rewritten after this value is set. If one of the tags is set and overview screen shows that the app is in single task mode. The activity will call the activity that the user has recently woken up.
Note: When using none or nerver, the activity must be set to launchMode = "standard". If this attribute is not set, the documentLaunchMode = "none" attribute will be used.
Remove Tasks
By default, when an activity is finished, its document tasks will be automatically removed from the overview screen. However, you can also set android: the excludeFromRecents attribute is true to remove a task from overview screen.
By setting the android: maxRecents attribute as an integer value in the tag, you can set the minimum value of the task that your app can include in overview screen. The default value is 16, the default maximum value is 50, and the memory may be 25. when the task of an app in overview screen reaches the maximum value, the tasks that are least recently used will be removed from overview screen.
Use the AppTask class to remove tasks
Create a task in an activity in overview screen. You can call the finishAndRemoveTask () function to describe when to remove a task and end the association between all activitys.
Example:
<span style="font-family:Microsoft YaHei;font-size:14px;">public void onRemoveFromRecents(View view) { // The document is no longer needed; remove its task. finishAndRemoveTask();}</span>
Note: The FLAG_ACTIVITY_RETAIN_IN_RECENTS Tag is rewritten using the finishAndRemoveTask () function, as described below.
Reserve finished tasks
If you want to retain a task in overview screen, you can add flag: FLAG_ACTIVITY_RETAIN_IN_RECENTS to the Intent of the activity even if the activity to be started has been completed.
Example:
<span style="font-family:Microsoft YaHei;font-size:14px;">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;}</span>
Similarly, setting property: android: autoRemoveFromRecents to false in the <activity> label of the mainfest file also has the same effect.