title: How to make notifyChange() work between two activities?
body: <p>I have an activity ActitvityA that holds a listview populated by a CursorLoader. I want to switch to ActivityB and change some data and see those changes reflected in listview in ActivityA.</p>
  
  <pre><code>public class ActivityA implements LoaderManager.LoaderCallbacks&lt;Cursor&gt;
  { 
      @Override
      public void onCreate(Bundle savedInstanceState)
      {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_a);
          getSupportLoaderManager().initLoader(LOADER_ID, null, this);
          mCursorAdapter = new MyCursorAdapter(   
              this,
              R.layout.my_list_item,
              null,
              0 );
      }
          .
          .
          .
  
      /** Implementation of LoaderManager.LoaderCallbacks&lt;Cursor&gt; methods */
      @Override
      public Loader&lt;Cursor&gt; onCreateLoader(int loaderId, Bundle arg1) {
          CursorLoader result;
          switch ( loaderId ) {           
          case LOADER_ID:
              /* Rename v _id is required for adapter to work */
              /* Use of builtin ROWID http://www.sqlite.org/autoinc.html */
              String[] projection = {
                      DBHelper.COLUMN_ID + " AS _id",     //http://www.sqlite.org/autoinc.html
                      DBHelper.COLUMN_NAME    // columns in select
              }
              result = new CursorLoader(  ActivityA.this,
                                          MyContentProvider.CONTENT_URI,
                                          projection,
                                          null,
                                          new String[] {},
                                          DBHelper.COLUMN_NAME + " ASC");
              break;
          default: throw new IllegalArgumentException("Loader id has an unexpectd value.");
      }
      return result;
  }
  
  
      /** Implementation of LoaderManager.LoaderCallbacks&lt;Cursor&gt; methods */
      @Override
      public void onLoadFinished(Loader&lt;Cursor&gt; loader, Cursor cursor) {
          switch (loader.getId()) {
              case LOADER_ID:
                  mCursorAdapter.swapCursor(cursor);
                  break;
              default: throw new IllegalArgumentException("Loader has an unexpected id.");
          }
      }
          .
          .
          .
  }
  </code></pre>
  
  <p>From ActivityA I switch to ActivityB where I change the underlying data.</p>
  
  <pre><code>// insert record into table TABLE_NAME
  ContentValues values = new ContentValues();
  values.put(DBHelper.COLUMN_NAME, someValue);
  context.getContentResolver().insert( MyContentProvider.CONTENT_URI, values);
  </code></pre>
  
  <p>The details of MyContentProvider:</p>
  
  <pre><code>public class MyContentProvider extends ContentProvider {
      .
      .
      .
  
      @Override
      public Uri insert(Uri uri, ContentValues values) {
          int uriCode = sURIMatcher.match(uri);
          SQLiteDatabase database = DBHelper.getInstance().getWritableDatabase();
          long id = 0;
          switch (uriType) {
          case URI_CODE:
              id = database.insertWithOnConflict(DBHelper.TABLE_FAVORITE, null, values,SQLiteDatabase.CONFLICT_REPLACE);
              break;
          default:
              throw new IllegalArgumentException("Unknown URI: " + uri);
          }
          getContext().getContentResolver().notifyChange(uri, null);  // I call the notifyChange with correct uri
          return ContentUris.withAppendedId(uri, id);
      }
  
  
      @Override
      public Cursor query(Uri uri,
                          String[] projection,
                          String selection,
                          String[] selectionArgs,
                          String sortOrder) {
  
          // Using SQLiteQueryBuilder instead of query() method
          SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
  
          int uriCode = sURIMatcher.match(uri);
          switch (uriCode) {
          case URI_CODE:
              // Set the table
              queryBuilder.setTables(DBHelper.TABLE_NAME);
              break;
          default:
              throw new IllegalArgumentException("Unknown URI: " + uri);
          }
          SQLiteDatabase database = DBHelper.getInstance().getWritableDatabase();
          Cursor cursor = queryBuilder.query( database, projection, selection, selectionArgs, null, null, sortOrder);
          // Make sure that potential listeners are getting notified
          cursor.setNotificationUri(getContext().getContentResolver(), uri);
          return cursor;
      }
  }
  </code></pre>
  
  <p>As far as my knowledge goes this should be sufficient. But it does not work. <strong>Upon returning to ActivityA the listview is unchanged</strong>.</p>
  
  <p>I have followed things with debugger and this is what happens.</p>
  
  <p>First visit ActivityA, the methods that are called in that order</p>
  
  <pre><code>MyContentProvider.query()    
  ActivityA.onLoadFinished()
  </code></pre>
  
  <p>The listview displays the correct values.
  And now I switch to activityB and change the data</p>
  
  <pre><code>MyContentProvider.insert()  // this one calls getContext().getContentResolver().notifyChange(uri, null);
  MyContentProvider.query()
  //As we can see the MyContentProvider.query is executed. I guess in response to notifyChange().
  // What I found puzzling why now, when ActivityB is still active ?
  </code></pre>
  
  <p>Return to ActivityA</p>
  
  <pre><code>!!! ActivityA.onLoadFinished() is not called    
  </code></pre>
  
  <p>I have read anything I could about this, took a close look at a lot of stackoverflow questions yet all those question/answers revolve around setNotificationUri() and notifyChangeCombo() which I implemented. Why does this not work across activities?</p>
  
  <p>If for example force refresh in ActivityA.onResume() with </p>
  
  <pre><code>getContentResolver().notifyChange(MyContentProvider.CONTENT_URI, null, false);
  </code></pre>
  
  <p>then it refreshes the list view. But that would force refresh on every resume regardless if data was changed or not.</p>