Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7518899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:48:58+00:00 2026-05-30T01:48:58+00:00

i am using a ContentObserver to listen for changes in the contacts database. now

  • 0

i am using a ContentObserver to listen for changes in the contacts database. now i realized that the onChange() method gets randomly called, even if i have not made any changes to the contacts. i suspect this is somehow related to the automatic contact syncing (even though there are no real changes to the contacts at this point).

is there a possibility to get notified only if there are real changes in the contacts, made by the user?

thx simon

public class ContactsObserver extends ContentObserver {
private final static String TAG = ContactsObserver.class.getSimpleName();

private Context ctx;
private List<ContactsChangeListener> listeners = new ArrayList<ContactsChangeListener>();

private ContactsObserver(Context ctx) {
    super(new Handler());
    this.ctx = ctx.getApplicationContext();
    ctx.getContentResolver()
        .registerContentObserver(
                ContactsContract.Contacts.CONTENT_URI,  // uri
                false,                                  // notifyForDescendents
                this);                                  // observer
}

@Override
public void onChange(boolean selfChange) {
    Log.i(TAG, "Contacs change");
    for(ContactsChangeListener l : listeners){
        l.onContactsChange();
    }
}

@Override
public boolean deliverSelfNotifications() {
    return false; // set to true does not change anything...
}

public static ContactsObserver register(Context ctx){
    Log.d(TAG, "register");
    return new ContactsObserver(ctx);
}

public void unregister(){
    Log.d(TAG, "unregister");
    ctx.getContentResolver().unregisterContentObserver(this);
}

public void addContactsChangeListener(ContactsChangeListener l){
    listeners.add(l);
}

public interface ContactsChangeListener{
    void onContactsChange();
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T01:48:59+00:00Added an answer on May 30, 2026 at 1:48 am

    ok, since no one seems to have an answer to this question, here is what i’ve done:

    when creating the observer, i load all the contacts into a cache. then, on every onChange() event, i load the contacts again and compare them to the cached ones to see if there is a difference or not.

    not the most elegant solution, but it works at least…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using C#, I need a class called User that has a username, password, active
Using Entity Framework CodeFirst, how do I create a created datetime column that gets
Using ASP.NET MVC there are situations (such as form submission) that may require a
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
Using the following as an example (with $db being a previously created database connection
Using the following database table structure: Order Table: OrderId OrderName OrderItem Table: OrderId ItemId
Using report builder 3.0, I have a report that queries a cube. How do
Using CRM 4, I have an entity form that contains a tab with an
I'm trying to get the call I just made/received. For that I'm using BroadcastReceiver
Using ruby(1.8.7) , rails(2.3.8) , rspec(1.3.1) and rspec-rails(1.3.3) how do I test a method

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.