In Android programming, what exactly is a Context
class and what is it used for?
I read about it on the developer site, but I am unable to understand it
Context
means component (or application) in various time-period. If I do eat so much food between 1 to 2 pm then my context of that time is used to access all methods (or resources) that I use during that time. Content is a component (application) for a particular time. The Context
of components of the application keeps changing based on the underlying lifecycle of the components or application.
For instance, inside the onCreate() of an Activity
,
getBaseContext()
-- gives the context
of the Activity
that is set (created) by the constructor of activity.
getApplicationContext()
-- gives the Context
setup (created) during the creation of application.
Note:
holds all Android Components.
..
..
..
..
It means, when you call getApplicationContext()
from inside whatever component, you are calling the common context of the whole application.
Context
keeps being modified by the system based on the lifecycle of components.