The google docs point out not to use the CursorAdapters
first constructor,
CursorAdapter(Context context, Cursor c)
There are only two other options,
CursorAdapter(Context context, Cursor c, boolean autoRequery)
which says
Constructor that allows control over auto-requery. It is recommended you not use this, but instead CursorAdapter(Context, Cursor, int). When using this constructor, FLAG_REGISTER_CONTENT_OBSERVER will always be set.`
and
CursorAdapter(Context context, Cursor c, int flags)`
which says it is the recommended constructor.
Problem is there are only two flags to use with the last constructor here, FLAG_AUTO_REQUERY
(int 1) and FLAG_REGISTER_CONTENT_OBSERVER
(int 2).
Using FLAG_AUTO_REQUERY
doesn't make sense because I am now using a CursorLoader in which to manage it in the background as well as update it. With FLAG_REGISTER_CONTENT_OBSERVER
, it says its not needed when using CursorLoader
.
Now I ask, what integer do I pass CursorAdapter(Context context, Cursor c, int flags)
in order to make it work fine with my CursorAdapter
? Whats worrying me is how to correctly manage the old cursor. I am not really sure the correct way to do this.
If I use FLAG_REGISTER_CONTENT_OBSERVER
, then I must do something with onContentChanged()
, but when using swapCursor()
in my LoaderManager
, since the cursor is not closed, I could just do adapter.swapCursor(cursor).close()
. But would that conflict with onContentChanged()
in CursorAdapter
? Goal is to not cause any memory leaks and be efficient.