如何加载所有与Android的最短时间接触 [英] How load all the contacts with minimum time in Android

查看:110
本文介绍了如何加载所有与Android的最短时间接触的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中获得的联系人花费很长的时间来加载。

In my project getting contacts is taking a long time to load.

  • 有什么方法可以减少患上接触
  • 的时间
  • 假设有1000个联系人在我的手机。
  • 右键现在它正在采取超过2分钟加载的所有联系人

我怎样才能减少加载接触的时间呢?  有什么想法吗?

How can I reduce the time to load contacts ? Any Thoughts?

我在编程的初始方法中提到的以下链接:

I referred to the the following link when programming the initial method.

http://www.$c$crzheaven.com/2011/06/13/get-all-details-from-contacts-in-android/

推荐答案

总时间将取决于你试图从联系人表访问哪些字段。     访问较少的领域意味着更少的循环,少加工,从而更快的结果。

Total time will depend upon what fields you are trying to access from the Contacts table. Accessing less field means less looping , less processing and hence faster results.

此外,加快您的联系人提取操作,您可以使用,而不是在ContentResolver的每次调用查询ContentProvideClient。这会让你查询的特定表而不是查询首先为所需的ContentProvider,然后表。

Also to speed up your contacts fetch operation you can use the ContentProvideClient instead of calling query on ContentResolver every time. This will make you query the specific table rather than querying first for the required ContentProvider and then to table.

创建ContentProviderClient的一个实例

Create an instance of ContentProviderClient

ContentResolver cResolver=context.getContextResolver();
ContentProviderClient mCProviderClient = cResolver.acquireContentProviderClient(ContactsContract.Contacts.CONTENT_URI);

然后再用这个mCProviderClient获取联系人(从任意的ContentProvider数据)数据呼叫。     例如,在下面的方法,我访问只有一个字段。

Then reuse this mCProviderClient to get Contacts(data from any ContentProvider) data on your call. For example in following method, I am accessing only one field.

private ArrayList<String> fetchContactsCProviderClient()
    {
        ArrayList<String> mContactList = null;
        try
        {
            Cursor mCursor = mCProviderClient.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
            if (mCursor != null && mCursor.getCount() > 0)
            {
                mContactList = new ArrayList<String>();
                mCursor.moveToFirst();
                while (!mCursor.isLast())
                {
                    String displayName = mCursor.getString(mCursor.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME));
                    mContactList.add(displayName);
                    mCursor.moveToNext();
                }
                if (mCursor.isLast())
                {
                    String displayName = mCursor.getString(mCursor.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME));
                    mContactList.add(displayName);
                }
            }

            mCursor.close();
        }
        catch (RemoteException e)
        {
            e.printStackTrace();
            mContactList = null;
        }
        catch (Exception e)
        {
            e.printStackTrace();
            mContactList = null;
        }

        return mContactList;
    }

这篇关于如何加载所有与Android的最短时间接触的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆