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 5951521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:32:57+00:00 2026-05-22T17:32:57+00:00

I have a big performance issue in my app. After going through traceview i

  • 0

I have a big performance issue in my app. After going through traceview i found that most of my app’s performance has been consumed by cursors. So i was wondering is there any alternative to Cursors for dealing with device contact list. And if there is no alternative then please advise me how to deal with cursors so it won’t slow down your app.

Please HELP!!

Thanks.

This part of my code has performance issue :-

public void getDisplayName()
{       
    Cursor c1 = this.getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);

    String personName = null, number = null;
    try 
    {
        Log.e(TAG, "I am here!!");
        if(c1.getCount() > 0)
        {
            Log.e(TAG, "I am here2!!");
            while(c1.moveToNext())
            {
                HashMap<String,String> item = new HashMap<String,String>();
                String id = c1.getString(c1.getColumnIndex(Contacts._ID));
                personName = c1.getString(c1.getColumnIndex(Contacts.DISPLAY_NAME));
                item.put("Name", personName);
                Cursor cur = this.getContentResolver().query(CommonDataKinds.Phone.CONTENT_URI, null, CommonDataKinds.Phone.CONTACT_ID +" = ?", new String[]{id}, null);
                while(cur.moveToNext())
                {
                    Log.e(TAG, "I am here!!3");
                    number = cur.getString(cur.getColumnIndex(CommonDataKinds.Phone.NUMBER));
                    item.put("Number", number);
                }
                displayName.add(item);          
            }
        }
    }
    finally
    {
        c1.close();
    }
}
  • 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-05-22T17:32:58+00:00Added an answer on May 22, 2026 at 5:32 pm

    How to fetch a contact name and number without using Cursors?

    That is not possible.

    I have a big performance issue in my app.

    Rather than using a single query, you use N+1 queries, where N is the number of rows returned by the other query. This is guaranteed to give you poor performance compared to just doing a single query.

    You can get the user’s name and _ID along with the phone numbers:

        String[] PROJECTION=new String[] { Contacts._ID,
                                            Contacts.DISPLAY_NAME,
                                            Phone.NUMBER
                                            };
        Cursor c=a.managedQuery(Phone.CONTENT_URI, PROJECTION, null, null, null);
    

    Also, never call getColumnIndex() in a loop, since the value never changes.

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

Sidebar

Related Questions

I recently discovered a pretty big performance issue in my app that was due
How would you maintain the legacy applications that: Has no unit tests have big
We have a web app + web site, which has performance issues. I have
I have a big jQuery code and I am thinking at speed performance of
I have big issue with url-rewriting for IIS 7.0. I've written simple module for
I have big system that make my system crash hard. When I boot up,
I have big problem when I am trying to deploy my app over clickonce.
I have big element at the top of the webpage that sides down with
I'm creating an app that will have a fair amount of users. Everytime someone
we have some performance issue with a program, I traced tsql using sql server

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.