Android Programming: The Big Nerd Ranch Guide, 5th Edition
by Bryan Sills, Brian Gardner, Kristin Marsicano, Chris Stewart
Challenge: No Untitled Crimes
It is impossible to solve a crime if you do not know what crime occurred. But if you open the detail view for a crime, erase its title, and navigate back to the list view, you will save a crime with no name.
For this challenge, while in CrimeDetailFragment, prevent the user from navigating back to the list if the selected crime’s title is blank. Using an OnBackPressedCallback, you can override the default Back button behavior. If the title is blank, give the user a hint that they should provide a description of the crime.
Some developer documentation that will be helpful for this challenge is at developer.android.com/guide/navigation/navigation-custom-back.
When using an OnBackPressedCallback, no ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access