Single Activity: Fragment Boss

In GeoQuiz, you had one activity (MainActivity) start another activity (CheatActivity). In CriminalIntent, you are instead going to use a single activity architecture. An app that uses single activity architecture has one activity and multiple fragments. The activity’s job is to swap fragments in and out in response to user events.

To implement the navigation from CrimeListFragment to CrimeFragment in response to the user pressing on a crime in the list, you might think to initiate a fragment transaction on the hosting activity’s fragment manager in CrimeListFragment’s CrimeHolder.onClick(View). This onClick(View) would get MainActivity’s FragmentManager and commit a fragment transaction that replaces ...

Get Android Programming: The Big Nerd Ranch Guide, 4th Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.