If you tried testing the overview screen with CriminalIntent and sharing crime data with other apps, you may have noticed some interesting behavior. 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 23.14).
The implicit intent chooser creates a new, separate task for activities launched with the android.intent.action.SEND
or android.intent.action.SEND_MULTIPLE
actions.
This behavior uses a notion called concurrent documents. Concurrent documents allow any number of tasks to be dynamically created for an app at runtime. Note that this behavior was introduced on Android Lollipop (API level 21), so if you test it on an older device you will not see the concurrent documents in the overview screen. 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 task in the overview screen (Figure 23.15).
You can start multiple “documents” (tasks) from your own app 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=".MainActivity"
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 will be 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.
18.118.200.136