I am using The Big Nerd Ranch Guide Android Programming. I completed the CriminalIntent project.
This is a method sequence being followed:
CrimeLab.get(getActivity())
get
is a static method in CrimeLab
class. It returns an instance of the CrimeLab
class.
This is the get
method:
public static CrimeLab get(Context context) {
if(sCrimeLab == null) {
sCrimeLab = new CrimeLab(context);
}
return sCrimeLab;
This is the CrimeLab constructor:
private CrimeLab(Context context) {
//mContext is a Context instance
mContext = context.getApplicationContext();
//mDatabase is a SQLiteDatabase instance
mDatabase = new CrimeBaseHelper(mContext).getWritableDatabase();
}
The CrimeBaseHelper (extends SQLiteOpenHelper) constructor:
public CrimeBaseHelper(Context context) {
super(context, DATABASE_NAME, null, VERSION);
}
So, the Activity obtained in the getActivity()
is ultimately passed to the constructor to the CrimeBaseHelper to create a SQLiteOpenHelper instance.
What I'm trying to understand is... what does the SQLiteOpenHelper constructor do with the Activity passed as Context?
What else could be passed as a Context to the SQLiteOpenHelper constructor?