android - 如何加快访问 Android 上的联系人?

标签 android contacts

在我看来,在 Android 上访问联系人是如此缓慢,而且不必要地涉及游标。如何加速?

最佳答案

1.当您第一次阅读联系人时,您可能会减少一些属性(property)。

2.读取一类属性时,可以使用游标。

private static final String[] CONTACTOR_ION = new String[]{  
ContactsContract.CommonDataKinds.Phone.CONTACT_ID,  
ContactsContract.Contacts.DISPLAY_NAME,  
ContactsContract.CommonDataKinds.Phone.NUMBER  
};  


Cursor phones = null;  
ContentResolver cr = getContentResolver();  
try {  
phones = cr  
        .query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI  
                , CONTACTOR_ION, null, null, "sort_key");  

if (phones != null) {  
    final int contactIdIndex = phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.CONTACT_ID);  
    final int displayNameIndex = phones.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);  
    final int phoneIndex = phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);  
    String phoneString, displayNameString, contactIdString;  
    while (phones.moveToNext()) {   
        phoneString = phones.getString(phoneIndex);  
        displayNameString = phones.getString(displayNameIndex);  
        contactIdString = phones.getString(contactIdIndex);  
    }  
}  
          } catch (Exception e) {  
Log.e(TAG, e.getMessage());  
} finally {  
if (phones != null)  
    phones.close();  
}

关于android - 如何加快访问 Android 上的联系人?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36347290/

相关文章:

android - 用于跨平台 GPU 编程的 C++、OpenCV 和 "what"

android - NavUtils.getParentActivityIntent() 抛出 "Activity does not have a parent activity name specified."

ios - 我正在检索所有联系人列表。然而它在 iPhone 5 中工作正常但在 iPhone 5s 中崩溃

iOS Contact app风格编辑用户信息表单

Android ArrayList<Location> 在 Activity 之间传递

android - 如何向用户的设备发送新的更新通知

安卓 : How to set monthly and weekly repeating calendar events(for selected days) using CalendarContract?

iOS:从地址簿中删除联系人时出错:[CNDataMapperContactStore executeSaveRequest:error:]

android - 在 android Activity 的抽屉导航中显示联系人

android - 当没有可用的联系人图像时显示图像