title: Onchange function of the content observer class being called more than once
body: <p>I am using a <code>contentObserver</code> to monitor the content of the <code>sms content provider</code>, I have put a <code>Log.d()</code> tag for debugging and the tag in the <code>logcat</code> is being seen more than once meaning the <code>onchange()</code> id being called more than once, how do I prevent this from happening. I have implemented the observer in a service running in the background.
  Here is the code</p>
  
  <pre><code>package com.messageHider;
  
   import android.app.Service;
   import android.content.ContentResolver;
   import android.content.Intent;
   import android.database.ContentObserver;
   import android.database.Cursor;
   import android.net.Uri;
   import android.os.Handler;
   import android.os.IBinder;
   import android.util.Log;
   import android.widget.Toast;
  
   public class smsSentService extends Service {
  ContentResolver contentResolver;
  Uri uri=Uri.parse("content://sms/");
  Handler handler;
  @Override
  public IBinder onBind(Intent arg0) {
      return null;
  }
  @Override
  public void onCreate() {
      contentResolver=getContentResolver();
      contentResolver.registerContentObserver(uri, true, new contentObserver(handler));
      Log.d("SENTSERVICE", "Service created");
      super.onCreate();
  }
  @Override
  public void onStart(Intent intent, int startId) {
      Log.d("SENTSERVICE", "Service started");
      super.onStart(intent, startId);
  }
  @Override
  public void onDestroy() {
      super.onDestroy();
  }
  public class contentObserver extends ContentObserver
  {
      public contentObserver(Handler handler) {
          super(handler);
  
      }
      @Override
      public void onChange(boolean selfChange) {
          Cursor cursor=contentResolver.query(uri, null, null, null, null);
          cursor.moveToFirst();
          String type=cursor.getString(cursor.getColumnIndex("type"));
          Log.d("THEMESSAGE", type);
          super.onChange(selfChange);
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <hr>