有没有更快的方法来读取android中的联系人?例如,我用光标的方法需要3-5秒才能读取30-50个联系人。这很长。快速阅读联系人android
Cursor cursor = managedQuery(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
while (cursor.moveToNext())
{
String contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
String hasPhone = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));
if (hasPhone.equalsIgnoreCase("1"))
hasPhone = "true";
else
hasPhone = "false" ;
if (Boolean.parseBoolean(hasPhone))
{
Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = "+ contactId,null, null);
while (phones.moveToNext())
{
names.add(cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME)));
numbers.add(phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)));
}
phones.close();
}
}
任何想法?
我这个答案达成一致。此外,你应该使用[CursorLoader](http://developer.android.com/reference/android/content/CursorLoader.html),因为它将完成UI线程的工作(如果你还没有这样做的话)。 – hwrdprkns 2012-04-20 17:32:06
是的,你可以做到这一点... :) – Kri 2012-04-20 17:35:10