Errata


#21

[size=150]Chapter 7[/size]

The description of the relationship between Activities and their views provided in the last paragraph after Figure 7.2 (beginning “Activities were not build to provide…”) is incorrect. Here’s a better replacement for that paragraph:

Activities were not build to provide this flexibility. An activity’s views may change at runtime, but the code to control those views must all live inside the activity. As a result, activities were tightly coupled to a particular screen used by the user.


#22

[size=150]Chapter 33, Tracking the Device’s Location[/size]

1 - Figure 33.1 depicts “API 17: Android 4.2 (Jelly Bean)” for the “Compile With” selection, but the text describes selecting the Google APIs version instead. The text here is correct. (Thanks to andrewebling for the tip.)

2- If the activity is destroyed and recreated, the user interface will (accurately) reflect that location manager is indeed posting location updates. Unfortunately, the fragment in the foreground will not have a run in mRun, and so it will not present the user with any updates. To fix the UI so that it presents some updates in this scenario, modify your RunFragment.onStart() as follows:

@Override
public void onStart() {
   super.onStart();
   if (mRunManager.isTrackingRun() && mRun == null) {
     mRun = new Run();
   }
   getActivity().registerReceiver(mLocationReceiver, new IntentFilter(RunManager.ACTION_LOCATION));
   Log.d(TAG, "onStart() called");
}

Thanks to RickDroid for the fix.


#23

[size=150]Chapter 13, Audio Playback[/size]

1- The resource qualifiers specified under Listing 13.2 are incorrect. Instead of e.g. “values-11”, use “values-v11”.

2- The ordering of code typed in the listings has an error. Listing 13.8 refers to the “mPlayer” instance variable, which is not defined until listing 13.9. (Thanks to rajohns for pointing out the error.)


#24

[size=150]Chapter 34, Local Databases with SQLite[/size]

1- Listing 34.21 comments the last four parameters to SQLiteDatabase.query() as being group by, order by, having, and limit. This is the wrong order! The proper order is group by, having, order by, then limit. (thanks to chdrya for the correction!)

2- Listing 34.23 makes references to a method with the following signature in RunManager:

public boolean isTrackingRun(Run run);

The chapter omits the implementation of this method, which is as follows:

    public boolean isTrackingRun(Run run) {
        return run != null && run.getId() == mCurrentRunId;
    }

Thanks to pmcconnell for pointing out the error.


#25

[size=150]Chapter 28[/size]

1- There is a typo below Listing 28.7: the text says action.intent.action.SEARCH. It should instead read android.intent.action.SEARCH. Thanks to Jonas1 for spotting this error.

2- Listing 28.8 omits the call to setHasOptionsMenu(true) shown in Listing 28.5. This is incorrect - the call should still be there.


#26

[size=150]Chapter 20[/size]

The listing in the “Deprecation in Android” for the more curious refers to a “getSize()” method on Display. This method does not exist.

The listing should instead read:

...
Point size;
display.getSize(size);
destWidth = size.x;
destHeight = size.y;
...

(thanks to idontdohumans for pointing out the error)


#27

[size=150]Chapter 24[/size]

Listing 24.6 specifies the layout file as activity_remote.xml. This is incorrect - it should read fragment_remote_control.xml instead.


#28

[size=150]Chapter 4[/size]

Immediately after Figure 4.5, the following text may be found:

“The top line in the stack trace is the line where you logged out the Exception. The line after that shows where the setter was called from - the implementation of onTextChanged(…). Double-click this line, and you will be taken to where you set the title to the hard-coded string. But do not get rid of the bug - you are going to use the debugger to find it again in a moment.”

Apart from describe a stack trace, this text bears no relation to what is going on at all.

Here is some better text:

“The top line in the stack trace is the line where you logged out the Exception. Two lines after that you can see where updateQuestion was called from within your onClick(…) implementation. Double click this line, and you will be taken to where you commented out the line to increment your question index. But do not get rid of the bug; you are going to use the debugger to find it again in a moment.”


#29

[size=150]Chapter 11[/size]

Listing 11.2 shows the top level resources tag with an xmlns:android attribute. This attribute is unnecessary, and should be deleted.


#30

[size=150]Chapter 29[/size]
At the top of page 475 in the printed edition, just prior to Listing 29.10, the text refers to a setServiceAlarm(boolean). There is no such method. The text should instead say setServiceAlarm(Context,boolean).

Thanks to android77 for the catch.


#31

[size=150]Chapter 3[/size]

Figure 3.12 shows an XML layout id for the top level FrameLayout. This id should be omitted.


#32

[size=150]Chapter 25[/size]

The crossed out text in Listing 25.9 says “button_shape_normal”. Listing 25.7 already changed this to “button_shape”, however. (Thanks to glenng.)