Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8160749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:20:47+00:00 2026-06-06T18:20:47+00:00

I have performance Issues when trying to load a list of contacts. this is

  • 0

I have performance Issues when trying to load a list of contacts.
this is the code:

public ContactList getContacts(String constraint)
{
    ContactList contactList = new ContactList();

    Uri uri = ContactsContract.Contacts.CONTENT_URI;

    if (constraint != null && constraint.equals("") == false)
    {
        uri = Uri.withAppendedPath(
                ContactsContract.Contacts.CONTENT_FILTER_URI, constraint);
    }

    ContentResolver cr = _context.getContentResolver();
    String sortOrder = DISPLAY_NAME + " COLLATE LOCALIZED ASC";
    // Cursor cur = cr.query(uri, null, null, null, sortOrder);
    String[] arrayOfString = new String[1];
    arrayOfString[0] = "1";
    Cursor cur = cr.query(uri, null, "has_phone_number=?", arrayOfString,
            sortOrder);

    if (cur.getCount() > 0)
    {

        setBaseContactList(contactList, cur);

    }
    cur.close();

    return contactList;
}

private void setBaseContactList(ContactList contactList, Cursor cur)
{
    String id;
    String name;
    String lookUpKey;
    String photoId;
    while (cur.moveToNext())
    {
        id = cur.getString(cur.getColumnIndex(DISPLAY_ID));
        name = cur.getString(cur.getColumnIndex(DISPLAY_NAME));

        photoId = cur.getString(cur.getColumnIndex(PHOTO_ID));
        lookUpKey = cur.getString(cur.getColumnIndex(LOOKUP_KEY));
        Contact c = new Contact(id, name, photoId, lookUpKey);
        contactList.addContact(c);
    }
}

looking at traceview I can see that
cur.getString(cur.getColumnIndex(“Some column name”));
Is taking it’s toll on the loading time

another thing that I can see while using traceview is that there are alot of callings to the method

String.equalsIgnoreCase()

my guess is that cur.getString is calling it.

Im thinking about putting all the values that are initiated onCreate() in an HT(ContactID, Contact) and then calling them after every selection from the contacts db using the user ids that were extracted.
I will cut down the usage 3 times which is prbbly good but is there a better solution?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T18:20:48+00:00Added an answer on June 6, 2026 at 6:20 pm

    On top of what @wildhemp suggested i would also try to query for specific columns as well and not pass “null” for all columns. I would also check how much cycles would be saved if i fetched values from hard-coded indexes (not best practice, but might speed the process a bit).

    For example:

    Cursor cur = cr.query(uri, 
                          new String[] {DISPLAY_ID, DISPLAY_NAME, PHOTO_ID, LOOKUP_KEY},
                          "has_phone_number=?", arrayOfString, sortOrder);
    while (cur.moveToNext())
    {
        id = cur.getString(0);
        name = cur.getString(1);
        photoId = cur.getString(2);
        lookUpKey = cur.getString(3);
    
        Contact c = new Contact(id, name, photoId, lookUpKey);
        contactList.addContact(c);
    }
    

    Another thing i would check is querying without any sorting, it is interesting to see how much extra cycles it uses for sorting, maybe there’s another, more efficient, way to do it.

    Although this is quite obvious i would still ask whether the Customer class is lightweight and if it does nothing but initializes its members. Also, that ContactList‘s addContact method simply adds another item to its wrapped or extended List<Customer>.

    General note, it is always good practice to surround any cursor related work with try/catch/finally to ensure that you close the cursor when you’re done.

    Anyway, when dealing with issues such as this one it is either the query is not efficient or the parsing loop is doing something wrong

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to track down some performance issues I have had with Django. There
I have a voip app that has a serious performance issues when it runs
I just started out with C and have very little knowledge about performance issues
Just like in this topic , I have a performance issue in dev mode
I've been trying to implement NSXMLParser and so far I've had memory issues, performance
I am trying to take a look into our database performance issues by making
This is a very simple game I'm trying to write but I have a
I am trying to code for our server in which I have to find
Due to performance issues (benchmarked) I'm trying to use another autoloader than the default
I have several performance issue in my website. I'm using asp.net mvc 2 and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.