In my project getting contacts is taking a long time to load.
- What are ways to reduce the time of getting contacts
- Assume there are 1000 contacts in my phone.
- Right now it is taking more than 2 minutes to load all the contacts
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.coderzheaven.com/2011/06/13/get-all-details-from-contacts-in-android/
Load Contact faster like other apps doing.
I have tested this code with multiple contacts its working fine and faster like other apps within
500 ms
(within half second or less) I am able to load1000+
contacts.Total time will depend upon what fields you are trying to access from the Contacts table.
Mange your query according to your requirement do not access unwanted fields. Accessing less field means less looping , less processing and hence faster results.
Accessing right table in contact it also help to reduce contact loading time.
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.
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.
Create an instance of ContentProviderClient
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.
BETTER SOLUTION HERE.....
CHEERS...:)
For loading the contacts with mininum time the optimum solution is to use the concept of projection and selection argument while querying the cursor for contacts.
this can be done in following way
With above method it took 400ms(less than second) to load contacts where as in normall way it was taking 10-12 sec.
For details imformation this post might help as i took help from it http://www.blazin.in/2016/02/loading-contacts-fast-from-android.html
I think this is a better solution:
for use it you need to call this lines once:
and when you want to get contact name by number, just use:
this algorithm is a bit faster...