01-Errata/Corrections

The code "Listing 3-19. Reading a Raw Resource" should instead be

Credit

Many thanks to Eduardo Berton for pointing out


String getStringFromRawFile(Activity activity)
   throws IOException
   {
      Resources r = activity.getResources();
      InputStream is = r.openRawResource(R.raw.test);
      String myText = convertStreamToString(is);
      is.close();
      return myText;
   }

   String convertStreamToString(InputStream is)
   throws IOException
   {
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      int i = is.read();
      while (i != -1)
      {
         baos.write(i);
         i = is.read();
      }
      return baos.toString();
   }

The drawable resource names, like other resource names cannot have a "-" in them. Replace them with an underscore "_" instead

Credit

Michael Eager

The listing instead should read


<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
   <item android:drawable="@drawable/colored_ball1" android:duration="50" />
   <item android:drawable="@drawable/colored_ball2" android:duration="50" />
   <item android:drawable="@drawable/colored_ball3" android:duration="50" />
   <item android:drawable="@drawable/colored_ball4" android:duration="50" />
   <item android:drawable="@drawable/colored_ball5" android:duration="50" />
   <item android:drawable="@drawable/colored_ball6" android:duration="50" />
   <item android:drawable="@drawable/colored_ball7" android:duration="50" />
   <item android:drawable="@drawable/colored_ball8" android:duration="50" />
</animation-list>

onStop() should go to onRestart() instead of onRestart going to onStop().

Credits

Ninh Nguyen

We will post a correct diagram soon here.

ImageView imgView = (ImageView)findViewById(R.id.imageView);

should be 

ImageView imgView = 
  (ImageView)findViewById(R.id.animationImage);

Credit

APress On line submitter

(Probably Michael Eager)

Thanks for pointing out.

This is caused by the discrepancy in the XML file and the java source code. You can adjust either. In the XML file the id was originally called "imageView" and there was a timing difference between when the code was copied from the source.

The code


   public void onDeleted(Context context, int[] appWidgetIds) {
      final int N = appWidgetIds.length;
      for (int i=0; i<N; i++) {
         BDayWidgetModel.removePrefs(context, appWidgetIds[i]);
      }
   }

should read


public void onDeleted(Context context, int[] appWidgetIds) 
{
     final int N = appWidgetIds.length;
     for (int i=0; i<N; i++) 
     {
       	BDayWidgetModel bwm =
       		BDayWidgetModel.retrieveModel(context, appWidgetIds[i]);
       	bwm.removePrefs(context);
     }
}

Credit

Adam from kku.ac.kr

This figure was smeared in production and we missed it. Here is what it should look like

One of the arrows got reversed in production. we missed this as well. Here is what it should look like

Click here to see the full size image

As we are revising chapters for ProAndroid3, I have seen slight inconsistencies in the code in Chapter 3. To correct this I have uploaded a sample project that you can download by refering to the ProAndroid 2 Downloads Page. The name of the sample project zip file is Ch03_TestProviders.zip. You should be able to download this zip file, unzip it and make a project in your eclipse environment. I regrest the delay in doing this and thank you very much for your patience.