1

I reference this link android developer training to implement for the retrieving contact detail with selection criteria

/*
     * Defines the selection clause. Search for a lookup key
     * and the Email MIME type
     */
    private static final String SELECTION =
            Data.LOOKUP_KEY + " = ?" +
            " AND " +
            Data.MIMETYPE + " = " +
            "'" + Email.CONTENT_ITEM_TYPE + "'";

@Override
    public Loader<Cursor> onCreateLoader(int loaderId, Bundle args) {
        // Choose the proper action
        switch (loaderId) {
            case DETAILS_QUERY_ID:
            // Assigns the selection parameter
            mSelectionArgs[0] = mLookupKey;
            // Starts the query
            CursorLoader mLoader =
                    new CursorLoader(
                            getActivity(),
                            Data.CONTENT_URI,
                            PROJECTION,
                            SELECTION,
                            mSelectionArgs,
                            SORT_ORDER
                    );
            ...
    }

When goes into change the contact name for example. Then in one case when adding contact is made by our application, cursor loader can't correctly detect the changes. I check the lookup key, that added contact key is different with others (for example : Orod-1340xxxxxxxx).

After searching the discussion, lookup key may change and suggest to use contact lookup uri with the lookup key. But the lookup uri cannot be used in above query. I need to query in Data table for the detail info.

How can i achieve that? Thanks a lot.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
rodent_la
  • 1,195
  • 4
  • 18
  • 38

1 Answers1

0

Try using CONTACT_ID instead of LOOKUP_KEY.

private static final String SELECTION =
    Data.CONTACT_ID + " = ? AND " +
    Data.MIMETYPE + " = '" + Email.CONTENT_ITEM_TYPE + "'";

You might stumble upon warnings not to use contact-ids and instead use lookup keys or lookup uris, but that's for persisting a contact reference into a database for long keeping, if you're app is currently up and running, and just recently queried for this contact-id, it's perfectly safe and ok to use it, it's even better to use contact-ids for this purpose since it's more stable as a standalone id.

See more info here and here

marmor
  • 27,641
  • 11
  • 107
  • 150