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. More: http://developer.android.com/reference/android/content/Context.html
and simple answer on stackoverflow gives by Sameer Segal.
As the name suggests, its the context of current state of the application/object. It lets newly created objects understand what has been going on. Typically you call it to get information regarding another part of your program (activity, package/application)
You can get the context by invoking
this(when in the activity class).
Typical uses of context:
- Creating New objects: Creating new views, adapters, listeners:
TextView tv = new TextView(getContext());
ListAdapter adapter = new SimpleCursorAdapter(getApplicationContext(), ...);
- Accessing Standard Common Resources: Services like LAYOUT_INFLATER_SERVICE, SharedPreferences:
- Accessing Components Implicitly: Regarding content providers, broadcasts, intent
Code Here Code explain on video , Watch on youtube:
Vogella gives example, you can check the size of the current device display via theThe
Contextclass also provides access to Android services, e.g., the alarm manager to trigger time based events.
Activities and services extend the
Contextclass. Therefore they can be directly used to access the
Context. More: http://www.vogella.com/tutorials/Android/article.html