2013-12-16 45 views
1

我使用Xamarin.Mobile組件爲Android獲取使用的代碼聯繫人:Xamarin.Mobile聯繫人API佔用了大量的時間,同時獲取聯繫人?

var book = new AddressBook (Activity) {PreferContactAggregation = true}; 
var contData = data.Data; 
var cur = Activity.ManagedQuery (contData, null, null, null, null); 
Contact myContact = null; 
var lookupKeyList = new List<string>(); 
while (cur.MoveToNext()) { 
lookupKeyList.Add (cur.GetString (cur.GetColumnIndexContactsContract.Contacts.InterfaceConsts.LookupKey))); 
} 

myContact = book.Where (c => c.Id == lookupKeyList [0]).First(); 

此代碼是選擇從電話簿中的聯繫人和接收上OnActivityResult方法的部分數據。 不幸的是,這段代碼是佔用了太多的時間在某些設備上,是對他人瞬間。我猜它與聯繫彙總有關,但我不確定。任何指針?

回答

0

聽起來像一個Android的問題,並不一定是Xamarin的問題。看看Getting name and email from contact list is very slow這個問題。這個答案所做的一件事就是在查詢中使用Projection來一次性獲取所有列。

+0

我可以在這裏使用的投影,但我需要區分接收到辦公電話,住宅電話,工作電子郵件,家庭電子郵件等數據在我上面使用的代碼,我只是得到了LookupKey場,並用它來獲得接觸來自Xamarin.Mobile Contacts API,它很容易爲我提供一個對象來區分數據到上面提到的字段中。 –

相關問題