This example runs in an android-9 emulator (2.3.1) but not in android-10 (2.3.3). All previous examples in the book run fine in 2.3.3.
Just a caution to others learning from the book. The book specifies that is was written and tested with version 2.3 (pg. xv), and based on the above example I would advise sticking with 2.3.1.
What I can't tell anyone is how to track down such errors. If you have more useful and specific information about how to track down the cause of such exceptions please feel free to comment. I didn't see anything useful in the stack trace. It was a runtime exception thrown on the managedQuery line:
Code:
Cursor c = managedQuery(allContacts, null, null, null, null);
Modifying the previous line allows the example to run in 2.3.3:
Code:
From:
Uri allContacts = Uri.parse("content://contacts/people");
To:
Uri allContacts = ContactsContract.Contacts.CONTENT_URI;
Sometimes when the documentation says something is deprecated you really must take note.
HTML Code:
http://developer.android.com/reference/android/app/Activity.html#managedQuery%28android.net.Uri,%20java.lang.String[],%20java.lang.String,%20java.lang.String[],%20java.lang.String%29
Code:
public final Cursor managedQuery (Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder)
Since: API Level 1
This method is deprecated.
Use CursorLoader instead.
Wrapper around query(android.net.Uri, String[], String, String[], String) that gives the resulting Cursor to call startManagingCursor(Cursor) so that the activity will manage its lifecycle for you. If you are targeting HONEYCOMB or later, consider instead using LoaderManager instead, available via getLoaderManager().