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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:09:19+00:00 2026-06-02T22:09:19+00:00

In my app, when launched I would like to display all the contacts with

  • 0

In my app, when launched I would like to display all the contacts with search filter option. I have achieved this but the problem is – while loading the contacts, it takes more time. How can I improve the efficiency of the code ? Below code snippet shows how I am retreiving contacts:

public ContactList newContactList(Context ctx)
{

ContactList contacts = new ContactList();

String id = "";

String sortOrder = ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC";

try
{

    this.cur = this.cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, sortOrder);       
    if (this.cur.getCount() > 0) {
        while (cur.moveToNext()) {
            Contact c = new Contact();
            id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
                if (Integer.parseInt(cur.getString(cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
                c.setId(id);
                c.setDisplayName(cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)));
                c.setPhone(this.getPhoneNumbers(ctx, id));
                c.setEmail(this.getEmailAddresses(id));
                c.setNotes(this.getContactNotes(id));
                c.setAddresses(this.getContactAddresses(id));
                c.setImAddresses(this.getIM(id));
                c.setOrganization(this.getContactOrg(id));
                //c.setPicture(loadContactPhoto(cr, cur.getLong(cur.getColumnIndex(CommonDataKinds.Photo.CONTACT_ID))));
                contacts.addContact(c);
            }               
        }
    }
    }
    catch(Exception e)
    {
        throw new IllegalStateException(e);
    }
    finally
    {
        cur.close();            
    }

    return(contacts);
}

ContactList is a class that returns ArrayList of all contacts, and with this arraylist I am setting it to my custom adapter class. I guess, because of fetching arraylist by itereating through cursor is taking much time. But, I would need this arraylist to filter the contacts based on search criteria and to display the custom contact list. Is there any way that I can improve the performance of the code?

  • 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-02T22:09:20+00:00Added an answer on June 2, 2026 at 10:09 pm

    Why don’t you use CursorAdapter ?
    http://developer.android.com/reference/android/widget/CursorAdapter.html

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

Sidebar

Related Questions

This app I completed around a year ago (!) but never launched it on
I'd like my app to have different functionality depending on whether it launched while
I am developing an Android App and would like to have a video file
Hello good Stack Overflow people, I do have a business problem and would like
I'd like to build a cocoa app and would like to have it opened
In the app I am making, I would like to take a Base64 image
I know many developers just do it like this: They start developing their app
I would like to check in which country the user is - I have
If I use com.apple.eawt.Application; even minimally as instantiating it like this: Application app =
I have a C# app that is launched via command line. Usually data is

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.