If you are running your apps on a Lollipop or later device, you may have noticed some interesting behavior with respect to CriminalIntent and the overview screen. When you opt to send a crime report from CriminalIntent, the activity for the app you select from the chooser is added to its own task rather than to CriminalIntent’s task (Figure 24.15).
On Lollipop forward, the implicit intent chooser creates a new, separate task for activities launched with the android.intent.action.SEND
or action.intent.action.SEND_MULTIPLE
actions.
(On older versions of Android, this does not happen, so Gmail’s compose activity would have been added directly to CriminalIntent’s task.)
This behavior uses a notion new in Lollipop called concurrent documents. Concurrent documents allow any number of tasks to be dynamically created for an app at runtime. Prior to Lollipop, apps could only have a predefined set of tasks, each of which had to be named in the manifest.
A prime example of concurrent documents in practice is the Google Drive app. You can open and edit multiple documents, each of which gets its own separate task in the overview screen (Figure 24.16). If you were to take the same actions in Google Drive on a pre-Lollipop device, you would only see one task in the overview screen. This is because of the requirement on pre-Lollipop devices to define an app’s tasks ahead of time in the manifest. It was not possible pre-Lollipop to generate a dynamic number of tasks for a single app.
You can start multiple “documents” (tasks) from your own app running on a Lollipop device by either adding the Intent.FLAG_ACTIVITY_NEW_DOCUMENT flag to an intent before calling startActivity(…) or by setting the documentLaunchMode
on the activity in the manifest, like so:
<activity android:name=".CrimePagerActivity" android:label="@string/app_name" android:parentActivityName=".CrimeListActivity" android:documentLaunchMode="intoExisting" />
Using this approach, only one task per document will be created (so if you issue an intent with the same data as an already existing task, no new task is created).
You can force a new task to always be created, even if one already exists for a given document, by either adding the Intent.FLAG_ACTIVITY_MULTIPLE_TASK
flag along with the Intent.FLAG_ACTIVITY_NEW_DOCUMENT flag before issuing the intent, or by using always
as the value for documentLaunchMode
in your manifest.
To learn more about the overview screen and changes that were made to it with the Lollipop release, check out developer.android.com/guide/components/recents.xhtml.
3.89.163.120