Actionbar should not show up button on tablet


I noticed when running the app on tablet, the actionbar still shows the Up/Home button, pressing it would cause the app to crash obviously. Just letting you guys know about it in case you want to fix it in future prints.


Yes, I just hit this. The reason is that in the manifest, the CrimeListActivity does not declare a parent activity, which makes NavUtils throw an exception. What is the resolution to this? Is it a special declaration in the manifest file or special run-time checking or both?

FWIW I fixed the problem by adding a check to onOptionsItemSelected in CrimeFragment

[code] public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
Activity a = getActivity();

            // Navigate back if possible, otherwise exit.
        	if (NavUtils.getParentActivityName(a) != null) {
        	} else {


Good catch! I’ll add it to the errata.

My preferred correction is this, inside onCreateView:

    public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.fragment_crime, parent, false);

        		NavUtils.getParentActivityIntent(getActivity()) != null) {


This code already appears in Listing 16.13 (p. 266 in print).