0

Lets say that i have 100 calls in my call log. I want to find the unique contacts (not numbers) that they have been called. The problem is that if a contact has two phone numbers (e.g. for Contact A i have a number for home and another for mobile) i will count that contact twice!

I tried the following. I am reading the call log. Then for each number of the call log i call the following custom function:

private String getContactID (String number) 
{
    String contactID = "";
    ContentResolver context = getContentResolver();

    /// number is the phone number
    Uri lookupUri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI,Uri.encode(number));

    String[] mPhoneNumberProjection = { PhoneLookup._ID };

    Cursor cur = context.query(lookupUri,mPhoneNumberProjection, null, null, null);
    try 
    {
       if (cur.moveToFirst()) 
       {
          contactID = cur.getString(0);
          return contactID;
       }
    } 
    finally 
    {
        if (cur != null)
            cur.close();
    }
    return contactID;
}

So then i have a calllog with contact ids and timestamp of the call and using a Set i get the unique... The above code works fine BUT the performance if very poor! I tried it in a new Google Nexus 4 and it takes about 1600 msec! I don't want to think about older smart phones...

Any suggestions?

user2116122
  • 13
  • 1
  • 7
  • This question seems to be considering your problem http://stackoverflow.com/questions/8654904/group-by-in-contentresolver-in-ice-cream-sandwich – Ivan Bartsov Mar 07 '13 at 09:44

1 Answers1

0

Use a background thread to lazy load the information in a ListView.

Initially fetch only about 10 results and display them in the list. That should happen fast. After that, in the background thread, keep on fetching information, 10 at a time, and keep on adding them to your list.

Swayam
  • 16,294
  • 14
  • 64
  • 102