【问题标题】:Xamarin.Mobile Contacts API takes up a lot of time while fetching contacts?Xamarin.Mobile 联系人 API 在获取联系人时占用大量时间?
【发布时间】:2013-12-16 15:47:51
【问题描述】:

我正在使用适用于 Android 的 Xamarin.Mobile 组件来使用代码获取联系人:

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 方法上接收数据的一部分。 不幸的是,这段代码在某些设备上占用了太多时间,而在其他设备上却是即时的。我猜它与联系人聚合有关,但我不确定。有什么指点吗?

【问题讨论】:

    标签: android xamarin.android xamarin xamarin.mobile


    【解决方案1】:

    听起来像是 Android 问题,不一定是 Xamarin 问题。看看问题Getting name and email from contact list is very slow。这个答案所做的一件事是在查询中使用投影来一次性获取所有列。

    【讨论】:

    • 我可以在这里使用投影,但我需要区分接收到工作电话、家庭电话、工作电子邮件、家庭电子邮件等的数据。在我上面使用的代码中,我只得到 LookupKey 字段和使用它从 Xamarin.Mobile 联系人 API 中获取联系人,该 API 可以轻松地为我提供一个对象来区分数据到我上面提到的字段中。
    猜你喜欢
    • 2012-03-21
    • 2013-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多