0

Problem: upon returning from a 2nd activity the first activity's listview does not reflect database changes made by the 2nd activity. If I make a trivial change to code (to make emulator happy) and refire the app the listview now accurately shows the database changes the 2nd Activity made during the last session.

The guts of the app:

MainActivity: extends Activity implements LoaderManager.LoaderCallbacks<Cursor>
=>onCreate: SimpleCursorAdapter set; getLoaderManager().initLoader(LOADER_ID, null, this)
=>onResume: super.onResume(); getLoaderManager().restartLoader(0, null, this)

...oh my gawd! There's the problem: initLoader and restartLoader are using different loader ID's.

This stumped me for the last five hours. Why I am leaving this question: in trying to solve my problem I didn't run into this answer (maybe it's just too bone-headed of a thing to suggest someone look for) but for the next person who stumbles in this unique way, here's a potential answer.

ross studtman
  • 936
  • 1
  • 8
  • 22
  • studmann Have you managed to solve this issue. My listview is also not refreshed although I correctly call setNotificationUri() and notofyChanges(). – f470071 Sep 23 '15 at 08:23

1 Answers1

0

Make sure LoaderManager ID's are the same in initLoader and restartLoader.

In addition to all the other posts by Alex and CommonsWare and all the rest of them that you will run into while searching for the solution to your failing-to-update listview, this is something else that might have happened to you.

During my searching for what could be wrong I also noted I had not implemented: cursor.setNotificationUri(getContext().getContentResolver(), uri);

(How do CursorLoader automatically updates the view even if the app is inactive?)

...two different tutorials I was following for how to implement content providers did not have that setContentNotificationUri in their providers' query methods; though they used a querybuilder and I did not (maybe setContentNotificationUri is included in the queryBuilder? Quick research didn't suggest that was the case).

Community
  • 1
  • 1
ross studtman
  • 936
  • 1
  • 8
  • 22