Note that there are some explanatory texts on larger screens.

plurals
  1. POContentResolver.notifyChange() doesn't work
    primarykey
    data
    text
    <p>Some background information:</p> <p>When I run my application, a foreground activity displays cached information from my local SQLite database and meanwhile a background service connects to server and gets some fresh information. When data is retrieved, the service fires up my ContentProvider's insert method, to update my local SQLite database. When the insert is done, I notify my ContentObserver (foreground activity) about the change to refresh the view. </p> <p>I know the insert works fine, because when I rerun the application manually I can see new data on my screen. Unfortunately, auto refresh does not work. Calling the method <code>ContentObserver.notifyChange()</code> fails. The weirdest thing is that it doesn't even stop on the <code>catch (Exception e)</code> line. It goes straight outside the <code>try/catch</code> block. I have no idea what's going on. <a href="http://developer.android.com/guide/developing/debugging/debugging-log.html" rel="nofollow">LogCat</a>, and console are quiet.</p> <p>Here's the part of code from <code>insert</code> method within my ContentProvider responsible for insert and change notification.</p> <pre><code>SQLiteDatabase sqlDB = db.getWritableDatabase(); try { long newID = sqlDB.insertOrThrow(StatsCollectorDatabase.TABLE_USERS, null, values); if (newID &gt; 0) { Uri newUri = ContentUris.withAppendedId(uri, newID); ContentResolver contentResolver = getContext().getContentResolver(); contentResolver.notifyChange(uri, null); // This is the line that fails return newUri; } else { throw new SQLException("Failed to insert row into " + uri); } } catch (SQLiteConstraintException e) { Log.i(DEBUG_TAG, "Ignoring constraint failure."); } catch (Exception e) { Log.i(DEBUG_TAG, e.getLocalizedMessage()); } </code></pre> <p>Here's the code from <code>onCreate</code> method in foreground Activity:</p> <pre><code>Cursor cursor = this.managedQuery(StatsCollectorProvider.CONTENT_URI, null, null, null, null); String[] columns = new String[] { StatsCollectorDatabase._USER_NAME, StatsCollectorDatabase._USER_DEVICE_ID }; int[] views = new int[] { R.id.name_entry, R.id.number_entry }; SimpleCursorAdapter adapter = new SimpleCursorAdapter(this.getApplicationContext(), R.layout.list_item, cursor, columns, views, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER); this.setListAdapter(adapter); Intent intent = new Intent(this.getApplicationContext(), UsersDownloaderService.class); this.startService(intent); </code></pre> <p>I tried googling, but found nothing relevant. How do I fix this problem? </p> <p>I can provide more code if this'll be necessary.</p>
    singulars
    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.
 

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