Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the use of SQLiteDatabase.CursorFactory in Android?

Tags:

android

sqlite

I have created a database by extending SQLiteOpenHelper class. And its created also. This is code I am pasting

public Imagehelper(Context context) {     super(context, DATABASE_NAME, null, SCHEMA_VERSION);      cntxt = context;     filename = Environment.getExternalStorageDirectory();      DATABASE_FILE_PATH_EXTERNAL = filename.getAbsolutePath()+File.separator+DATABASE_NAME;     Log.i("Log", ":"+DATABASE_FILE_PATH_EXTERNAL); } 

Here everything is working fine. But if you focus on the parameters pass in super super(context, DATABASE_NAME, null, SCHEMA_VERSION); . I am not able to understand the null parameter. I know here we have to pass the SQLiteDatabase.CursorFactory object.

But how?? And what is the use of that??

like image 961
Narendra Pal Avatar asked Jul 25 '12 05:07

Narendra Pal


1 Answers

The reason of passing null is you want the standard SQLiteCursor behaviour. If you want to implement a specialized Cursor you can get it by by extending the Cursor class( this is for doing additional operations on the query results). And in these cases, you can use the CursorFactory class to return an instance of your Cursor implementation. Here is the document for that

SQLiteDatabase.CursorFactory DOC

Used to allow returning sub-classes of Cursor when calling query.

like image 67
BBdev Avatar answered Oct 14 '22 02:10

BBdev