1

I'm refactoring an Android work-in-progress app to use the Loader framework, and since the data is all stored in the SQLite database I'm using the commonsware loaderex package and SQLiteCursorLoader rather than a ContentProvider layer.

The insert(..), update(..) etc methods in SQLiteCursorLoader have void return type. It would make my life easier and my code neater if they returned a long, being the autoincremented row id of the row in the table that had been amended.

I could probably hack SQLiteCursorLoader to do this, but I wondered if there was a design reason that it doesn't at the moment? in case I get stuck in and hit a big gotcha.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
ejoftheweb
  • 301
  • 1
  • 2
  • 10

1 Answers1

3

I wondered if there was a design reason that it doesn't at the moment?

Sure. Those methods do the actual work in an AsyncTask, and therefore cannot return the value that you seek.

You are welcome to do your own AsyncTask to perform those operations and deal with those values, assuming that the underlying SQLite APIs support it (I don't think you can get the value you want from an update, since there are multiple rows that might be affected). You would have to call onContentChanged() on the SQLiteCursorLoader yourself, to trigger the logic to re-query the database and deliver you a fresh Cursor.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491