What are the parameters for constructor of class cl_DBHandler which extends SQLiteOpenHelper in android?
i have created class cl_DBHandler
which extends SQLiteOpenHelper
. and i have created class my_srvc
which extends service
. i have intialise object m_DBHandler
of class cl_DBHandler
in service but while initialization object i have to pass parameters to cl_DBHandler(context, name, factory, version)
, i am not getting exactly what to pass in this.
i have pass like this cl_DBHandler(getappcontext(),"databasename.sqlite",null,1)
2nd thing: i am calling one function from class with help of m_DBHandler object
but i am getting value null of object m_DBHandler
at every call though i have i开发者_Python百科ntialise that object in service
.can anyone tell me or guide me to solve this problem.
Thanks in Advance--
Use the following constructor for your cl_DBHandler class
public static final String DATABASE_NAME = "MyDBName.db";
public static final int DATABASE_VERSION = 1;
public cl_DBHandler(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
In your service or activity:
cl_DBHandler m_DBHandler = new cl_DBHandler(this);
Then open your database:
SQLiteDatabase db;
try {
db = m_DBHandler.getWritableDatabase();
} catch (SQLiteException ex) {
db = m_DBHandler.getReadableDatabase();
}
// do anything you like for example:
Cursor cursor = db.rawQuery(strQuery, null);
精彩评论