3

I'm struggling with the following weird bug and could find out whether its source is in my code or in the Android-19 code.

I'm trying to query the content provider async using AsyncQueryHandler, but its onQueryComplete() never got called. When I went deeper and debugged the android source I noticed that the handleMessage() of the AsyncQueryHandler never gets called. Even so that the StartQuery() creates new message and posts it.

The following code runs from a worker thread. I'll appreciate any help.

private static final String[] PROJECTION_NAMES = { StructuredName.GIVEN_NAME, StructuredName.MIDDLE_NAME, StructuredName.FAMILY_NAME };
private static final String WHERE_NAMES = ContactsContract.Data.MIMETYPE + "='" + StructuredName.CONTENT_ITEM_TYPE + "' AND "
            + StructuredName.LOOKUP_KEY + "=?";


ContentResolver cr = GlobalContext.getAppContext().getContentResolver();
AsyncQueryHandler asyncQueryHandler = new AsyncQueryHandler(cr) {

        @Override
        protected void onQueryComplete(int token, Object cookie, Cursor c) {

            if (c == null)
                return;

            if (c.moveToFirst()) {
                do {
                    String firstName = c.getString(INDEX_GIVEN_NAME);
                    String middleName = c.getString(INDEX_MIDDLE_NAME);
                    String lastName = c.getString(INDEX_FAMILY_NAME);

                    if (!TextUtils.isEmpty(firstName) || !TextUtils.isEmpty(middleName) || !TextUtils.isEmpty(lastName)) {
                        if (TextUtils.isEmpty(firstName)) {
                            firstName = middleName;
                        } else if (!TextUtils.isEmpty(middleName)) {
                            firstName += " " + middleName;
                        }

                        contact.setFirstName(firstName);
                        contact.setLastName(lastName);
                        break;
                    }
                } while (c.moveToNext());
            }

            c.close();
        }
    };

    token++;

    asyncQueryHandler.startQuery(token, new Object(), ContactsContract.Data.CONTENT_URI, PROJECTION_NAMES, WHERE_NAMES,
            new String[] { contact.getPhoneBookId() }, null);
Nativ
  • 3,092
  • 6
  • 38
  • 69

0 Answers0