-5

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?

Squonk
  • 48,735
  • 19
  • 103
  • 135
Jeet Parekh
  • 740
  • 2
  • 8
  • 25

1 Answers1

0

Context allows access to application-specific resources and classes, as well as calls for application-level operations such as launching activities, broadcasting and receiving intents, etc. more details : Context ? What Context ?

BobyCloud
  • 244
  • 1
  • 4
  • 11