Android Question Contacts Changed Event

echapeta

Member
Licensed User
Longtime User
I need an efficient way to be alerted when the phone's contacts are changed.

Currently, I'm reading the contacts using ContactUtils (faster) and the Phone/Contacts (to get more info/fields).

I keep a Map with the ContactID and a Hash over the fields, and periodically I check for changes.

This process is very slow and resources consuming when you have more than 1000 or 2000 contacts.

Is there any way to monitor and get an event when something changes in the Contacts ?

I need an event driven way....

Thank You.
 

bsnqt

Active Member
Licensed User
Longtime User
I think you can use ContentObserver... If it is not possible in B4A you need to write a small library (Eclipse) using ContentObserver. Every time there is a change in Contacts, you will have an intent sent by your library with a specific action. Use BroadcastReceiver that listens for this intent (with specific action) in your B4A app. I have successfully listened to Contacts change in my app, using this solution.

It is similar to this task:
http://www.b4x.com/android/forum/threads/is-there-something-similar-to-contentobserver-in-b4a.32051/

Maybe there are better methods but I don't know. I believe experts in this forum will give you more advices.
 
Last edited:
Upvote 0

echapeta

Member
Licensed User
Longtime User
Erel,

Yes, ContactUtils took 2 secs, but If you need more fields, you must extract them for each Contact, this is time consuming.

Also, in order to generate the Hash and compare you must go Contact per Contact.

With 2000 contacts in a S2 it takes about 1 minute,

I use B4A in order to avoid Java and the Android OS, but if there is no other way, I will try to write a Library.

Thank You.
 
Upvote 0

echapeta

Member
Licensed User
Longtime User
Dear Erel,

I understand that in order to write a Library you need to do it in Java, at least I get this from the examples.

Yes, I get all the Contacts with CU, but anyway when you must loop in them in order to get the fields that CU doesn't provide and to generate and check the Hash, then you get into a very resources and time consuming activity.

Yes, you can do it Async or in another thread, anyway is slow and consumes resources.

As is with the available Libraries, without them, B4A would be very limited in functionality.

Thank You,
 
Upvote 0

echapeta

Member
Licensed User
Longtime User
Dear Erel,

I partially agree.

This happens because we are using a procedural programming model.

We need to periodically scan the contacts looking for changes, and many times just to found that there are not changes.

If we could get an event fired when something changes, and better, what Contact changed, we will go to and event driven programming model, a lot more efficient....

Thank You.
 
Upvote 0
Top