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 the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.