CriminalIntent 3e -> 4K Changelog

I didn’t take a listing by listing set of notes for changes, but did note some high level feature differences:

Additions

  • Ch. 11 - Room API added on top of SQLite Database

Modifications

  • Ch. 12 - single activity structure. The 3rd Edition had the CrimeListFragment hosted in one fragment and the CrimePagerFragment/CrimeDetailFragment hosted in a second fragment. The two activities maintained the back stack after the explicit intent. The 4th Edition refactors this structure to have just a single activity and replace fragments. Now, the back stack needs to be explicitly added to to maintain the navigation between fragments.

Deletions

  • ViewPager - The 3rd Edition had after selecting a crime from the list, a ViewPager hosted multiple CrimeFragments to allow for horizontal swiping between crime details without having to return to the list. This component reinforces the Adapter paradigm, but was mostly just highlighting another widget to leverage.
  • Toolbar Subtitle - Not necessary. Could have been added as a challenge to Ch. 14
  • Delete Crime Challenge - This was a good challenge to handle various situations. First, the crime needed to be removed from the database. Then the functionality needed to be added to the Callbacks interface to remove the fragment and update the RecyclerView. This would have been a nice challenge to add to Ch. 11 or Ch. 14
  • Swipe to Dimiss on RecyclerView - Connected to deleting a crime. Not necessary, but could have been a good hint as to additional RecyclerView features to add in.
  • Up Button - In Ch. 6 “How Android Sees Your Activities” the last line says Wondering about the Up button? We will discuss how to implement and configure this button in Chapter 14. Since CriminalIntent was refactored to be a single activity there is no longer the parent activity relationship so the Up button is removed. I do not see any reference in Ch. 14 to the Up Button. Jumping ahead to the solution for Ch. 29 with PhotoGallery, there is no parent activity noted in AndroidManifest.xml. This seems like a loss since we lose a feature, but also since from notifications we may navigate into our app at a point that is not our launcher activity. Are apps moving towards a single activity framework? PhotoGallery has two activities so it would seem not necessarily.
  • Two-Pane Layout - This seems like the biggest removal from the CriminalIntent app. The List-Detail view is alluded when discussing fragments in Ch. 8, but the reader never gets to implement this layout. The two-pane layout had both fragments side by side and proved the benefit of a Fragment architecture. In portrait mode we’d use the CrimeListFragment on its own or the CrimeFragment on its own. But in landscape mode, we could repackage both fragments to be displayed at the same time. The Callbacks interface allowed both scenarios to be handled cleanly on selecting a crime. Further, carrying the delete crime challenge through allowed for a thorough understanding of the fragment manager. Additionally, deciding how to handle rotation and the menu was an unintended good challenge.

Answering some of my own comments from above:

Yes, Android is now moving towards a single activity structure.

But this is not mentioned anywhere in the book. After completing the CriminalIntent app as structured in the book, I then went back and refactored to use the Jetpack Navigation Architecture Component. Using the new navigation framework, I was able to work within the single activity structure and add back in the Up button. The Navigation AC also allows for Deep Links to create the back stack which will provide the complimentary notification feature.

Thanks for posting this @jpaone!

My biggest miss on this edition are the view pager and the two-pane layout. I guess I’ll need to leverage to the 3rd edition and the web to write it in Kotlin :man_shrugging: