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 getApplicationContext(), getContext(), getBaseContext() or this (when in the activity class).
Typical uses of context:
Creating New objects: Creating new views, adapters, listeners:
TextView tv =newTextView(getContext());ListAdapter adapter =newSimpleCursorAdapter(getApplicationContext(),...);
Accessing Standard Common Resources: Services like LAYOUT_INFLATER_SERVICE, SharedPreferences:
Consider Person-X is the CEO of a start-up software company
There is a lead architect present in the company, this lead architectdoes all the work in the company which involves such as database, UIetc
Now the CEO Hires a new Developer
It is the Architect who tells the responsibility of the new hiredperson based on the skills of the new person that whether he willwork on Database or UI etc
Simpler terms ::
It's like access of android-activity to app's resource
It's similar to a when you visit a hotel, you want breakfast, lunch & dinner in suitable timings right ?
There are many other things you like during the time of stay. How youget these things?
You ask the room-service person to bring the things for you
Here room-service person is the context considering you are thesingle activity and the hotel to be your app, finally the breakfast, lunch &dinner to be the resources
Things that involve context are:
Loading a resource.
Launching a new activity.
Creating views.
obtaining system service.
Context is the base class for Activity, Service, Application .... etc
Another way to describe is, consider context as remote of a TV & channel's in the television are resources, services, using intents etc - - - Here remote acts as an access to get access to all the different resources into foreground.
So, Remote has access to channels such as resources, services, using intents etc ....
Likewise ..... Whoever has access to remote naturally has access to all the things such as resources, services, using intents etc
Different invoking methods by which you can get context
getApplicationContext()
getContext()
getBaseContext()
or this (when in the activity class)
Example:
TextView TV=newTextView(this);
this -> refers to the context of the current activity.