Android Programming The Big Nerd Ranch Guide by Bill Phillips, Chris Stewart, Kristin Marsicano (z-lib.org)

(gtxtreme123) #1

Chapter 24  More About Intents and Tasks


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.


Figure 24.16  Multiple Google Drive tasks on Lollipop


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.html.

Free download pdf