How to read all phone contacts in android faster?

1.2k views Asked by At

I am working on an application (API > 15) which reads all phone contacts and then suggests all people who are on our application.

Data required :
1. Phone numbers
2. Email ids

The flow is :
1. Read all phone contacts
2. Send them to the server
3. Match with existing contacts
4. Send the matched contacts back to client
5. Suggest the user those contacts.

Now issue is I have close to 2000 contacts in my phone. For that it is taking 46 sec. This is too much. I can't make the user wait so much.

Possible Solution :
Read contacts in several batches of 200 contacts each using different threads. Run them parallely and consolidate the results.

Issue
I tried it but still taking too much time. I think content resolver is thread safe. So it is still not able to service different thread requests parallely and taking same time. Infact a little more than before now.

I think there should be some other solution which all these messaging apps like whatsapp uses. Anyone have any idea?

I can post the code as well but it is the common default one only which everyone uses. I have done all type of optimisations there including not making any extra String variables which might interest android to run garbage collector again and again and increase processing time.

1

There are 1 answers

0
Ramdane Oualitsen On

Put everything in a service when the user launcher your app. do everything in background. once you finish popup something to the user. This is what am doing right now and I hope I help.