0

Im already read about context explanation and read context in others reference on google. but im need some practical explanation about context. this script

public MySQLiteHelper(Context context) {
    super(context, DATABASE_NAME, null, DATABASE_VERSION);
}

what does those context do ? why should need context need as parameter. thanks

navotera
  • 321
  • 1
  • 15

1 Answers1

4

SQLiteOpenHelper needs a Context to create or open an existing database. It uses this method to do so. But you could have see it yourself by opening the source code of the class.

db = mContext.openOrCreateDatabase(mName, mEnableWriteAheadLogging ?
    Context.MODE_ENABLE_WRITE_AHEAD_LOGGING : 0,
    mFactory, mErrorHandler);

Context is used almost everywhere in Android, mostly for accessing application resources, as well as performing various operations.

Eduard B.
  • 6,735
  • 4
  • 27
  • 38
  • this link would be explanation in those answer : https://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html – navotera May 23 '16 at 06:57
  • 1
    I'm glad if it's clearer to you now. I just added a link to `SQLiteOpenHelper`'s source code as well. Cheers! – Eduard B. May 23 '16 at 06:59