嗨我目前在做聯繫,如果我從接觸* (電子郵件,電話號碼和聯繫人姓名) *獲取詳細信息相關項目和它well.But的問題是,它需要很長的時間來獲取聯繫方式(包括來自社交網站同步的1000多名聯繫人)包括。因此,我爲此設置了一個Asynchronous Task
,並且它的表現不錯,但問題是由於很長時間才能完成提取過程,當我按後退按鈕它在異步任務期間崩潰。我的問題不會崩潰爲什麼這個提取的聯繫人花費了大量的時間。有辦法讓contact
更快。我的代碼來獲得接觸的細節低於獲取聯繫人詳細信息花費大量的時間在android?
public void readContact() {
contactname = new ArrayList<String>();
contactnumber = new ArrayList<String>();
companyname_one = new ArrayList<String>();
contactemail = new ArrayList<String>();
people = getContentResolver().query(
ContactsContract.Contacts.CONTENT_URI, null, null, null,
PhoneLookup.DISPLAY_NAME);
while (people.moveToNext()) {
int nameFieldColumnIndex = people
.getColumnIndex(PhoneLookup.DISPLAY_NAME);
String contact = people.getString(nameFieldColumnIndex);
if (contact == null) {
contactname.add("No contact Set");
} else {
contactname.add(contact);
}
String szId = people.getString(people
.getColumnIndexOrThrow(ContactsContract.Contacts._ID));
cursor_one = getContentResolver().query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
null,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID + "='"
+ szId + "'", null, null);
if (cursor_one.moveToNext()) {
String number = cursor_one.getString(cursor_one
.getColumnIndex(Phone.NUMBER));
contactnumber.add(number);
cursor_one.close();
} else {
contactnumber.add("no number");
cursor_one.close();
}
emails_value = getContentResolver().query(
Email.CONTENT_URI,
null,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID + "='"
+ szId + "'", null, null);
if (emails_value.moveToNext()) {
email_sorting = emails_value.getString(emails_value
.getColumnIndex(Email.DATA));
checkAll();
} else {
contactemail.add("no email");
emails_value.close();
}
}
people.close();
System.out.println("noz " + contactnumber);
System.out.println("name" + contactname);
System.out.println("email" + contactemail);
System.out.println("noz size " + contactnumber.size());
System.out.println("name size " + contactname.size());
System.out.println("contactemail size " + contactemail.size());
}
的checkAll()
方法給出的是電子郵件的圖案匹配如下
public boolean checkAll() {
boolean chkAll = true;
Pattern p1 = Pattern.compile("[email protected]+\\.[a-z]+");
Matcher m1 = p1.matcher(email_sorting.trim());
if (!m1.matches()) {
contactemail.add("no email");
contactemail_sort.add("no email");
emails_value.close();
chkAll = false;
} else {
contactemail.add(email_sorting);
contactemail_sort.add(email_sorting);
emails_value.close();
chkAll = true;
}
return chkAll;
}
好的建議,但你能告訴我一個自定義CursorAdapter的例子 – Ramz 2012-08-16 18:44:17
當然。當我有一段時間的時候,我會編輯一個。 – Stuporman 2012-08-16 19:27:27
okey謝謝,請儘快發佈:) – Ramz 2012-08-16 19:41:17