1
private static class OpenHelper extends SQLiteOpenHelper {
    OpenHelper(Context context) {
    super(context, DATABASE_NAME, null, DATABASE_VERSION);
}}

I cannot understand the meaning of type Context. I read the manual but can not understand.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Max Usanin
  • 2,479
  • 6
  • 40
  • 70

3 Answers3

2

Context is an interface!

According to source code:

Interface to global information about an application environment. This is an abstract class >whose implementation is provided by the Android system. It allows access to application-specific resources and classes, as well as up-calls for application-level operations such as launching activities, broadcasting and receiving intents, etc.

See http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.0.4_r1.2/android/content/Context.java#Context for the best understanding

Chirag
  • 56,621
  • 29
  • 151
  • 198
Alex Klimashevsky
  • 2,457
  • 3
  • 26
  • 58
0

Context refers to the context of the activity where the database object is created.

Let SampleClass be the activity in which you want to access the database.

SampleClass.this will be the argument to that constructor.

Rahmathullah M
  • 2,676
  • 2
  • 27
  • 44
0

Context, provided to SQLiteOpenHelper is used (among other) to obtain database path, calling

context.getDatabasePath();

So, the only reason to pass some custom context implementation is to override database location, as described in this topic: https://stackoverflow.com/a/9168969/716075

Community
  • 1
  • 1
StenaviN
  • 3,687
  • 24
  • 34