Note that there are some explanatory texts on larger screens.

plurals
  1. POOnchange function of the content observer class being called more than once
    primarykey
    data
    text
    <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>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload