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


Run NerdLauncher, and you will see a RecyclerView populated with activity labels (Figure 24.4).


Figure 24.4  All your activities are belong to us


Creating Explicit Intents at Runtime


You used an implicit intent to gather the desired activities and present them in a list. The next step is to
start the selected activity when the user presses its list item. You will start the activity using an explicit
intent.


To create the explicit intent, you need to get the activity’s package name and class name from
the ResolveInfo. You can get this data from a part of the ResolveInfo called ActivityInfo.
(You can learn what data is available in different parts of ResolveInfo from its reference page:
developer.android.com/reference/android/content/pm/ResolveInfo.html.)


Update ActivityHolder to implement a click listener. When an activity in the list is pressed, use the
ActivityInfo for that activity to create an explicit intent. Then use that explicit intent to launch the
selected activity.

Free download pdf