I'm using the cursor.setExtras(bundle) function in my android project. It is working fine for api level 23. Since this function is available only for api level 23 and above, I've to find the alternative to set the Extra Bundle to Cursor.
Asked
Active
Viewed 1,008 times
0
-
Is this for use within just your app? Or are you passing this Cursor to other apps; e.g., from a ContentProvider? – Mike M. Jan 06 '16 at 07:51
-
`abstract Bundle Cursor#respond(Bundle extras)` – pskink Jan 06 '16 at 09:11
-
Hi @MikeM. The use of this confined to my app. – Rohit Pal Jan 06 '16 at 10:29
-
Hello @pskink ! It will be a great help if you provide the snippet of implementation as I was using it like `mycursor.setExtras(bundle)`. – Rohit Pal Jan 06 '16 at 10:32
-
`respond` method has the same API – pskink Jan 06 '16 at 10:35
-
@pskink , when i use it like you said `cursor.respond(bundle)` , my app crashes with `java.lang.IllegalStateException: Couldn't read row 0, col 6 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it ` – Rohit Pal Jan 06 '16 at 11:11
-
@RohitPal, which Cursor did you use? MatrixCursor or Cursor from database? – Yevhen Vasilenko Oct 05 '16 at 16:24
2 Answers
0
You can't use cursor.setExtras() in api below 23, so we need to use something else. I think there is a way to achieve this by using MatrixCursor:
MatrixCursor extras = new MatrixCursor(new String[] { "_id", "title" });
extras.addRow(new String[] { "-1", "New Template" });
extras.addRow(new String[] { "-2", "Empty Template" });
Cursor[] cursors = { extras, cursor };
Cursor extendedCursor = new MergeCursor(cursors);
This question help me to find an alternative solution: How to insert extra elements into a SimpleCursorAdapter or Cursor for a Spinner?
0
You can instead override the getExtras() method and return the Bundle there. This works because getExtras() is available from api level 1.
MatrixCursor c = new MatrixCursor(new String[] { "_id", "title" })
{
@Override
public Bundle getExtras() {
return new Bundle();
}
};

Wirling
- 4,810
- 3
- 48
- 78