在我看来,访问Android上的联系人是如此之慢,并且不必要地涉及游标。如何加速?
答案 0 :(得分:0)
1.当您第一次阅读联系人时,您可能会减少一些财产。
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();
}