I was already struggling with some code from Professional Android 2
App Development that uses the managedQuery() method of Activity when I
noticed that the method is deprecated anyway. The documentation says
to use CursorLoader instead, and from what I can gather, LoaderManager
also seems to be involved. The way the code stands, I somehow need
first to get a Cursor that contains the data in
ContactsContract.Contacts.

Here's the code I'm needing to change:

First, in onCreate() in my ContactSelector activity:

<code>Intent i = getIntent();

        final Uri data = i.getData();
        // managedQuery() is deprecated
        final Cursor c = managedQuery(data, null, null, null, null);

        String[] from = {ContactsContract.Contacts.DISPLAY_NAME};
        int[] to = {R.id.contact_name};

        SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
                        R.layout.contact_item_text_view, c, from, to);

</code>

The point here is that I need a cursor to feed into
SimpleCursorAdapter (or some other class that allows me to populate my
list of contact_item_text_view text views).

Then in the parent activity that calls ContactSelector using
startActivityForResult(), I have this private method that gets called
from onActivityResult (where data is of course the Intent that's
passed into onActivityResult()):

<code>
private void addPlayer(Intent data) {
        Uri contactData = data.getData();
        Cursor c = managedQuery(contactData, null, null, null, null);
        c.moveToFirst();
        String name = "contact " +
c.getString(c.getColumnIndexOrThrow(ContactsContract
                        .Contacts._ID)) + ": " +
c.getString(c.getColumnIndexOrThrow(ContactsContract
                        .Contacts.DISPLAY_NAME));
        // TODO
        Toast nameMessage = Toast.makeText(this, name,
Toast.LENGTH_SHORT);
                nameMessage.show();
    }
</code>
Basically, I just need a good way to populate my contact list in the
ContactSelector activity, then to receive the data back from the
parent activity. The toast is just there for the moment to show me
what I'm getting back.

If it matters, I'm going to need to retrieve not only names but also
phone numbers in the end, so some technique that would make it as easy
as possible to deal with that aspect would also be nice.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to