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
Simple Example to understand context
in android :
Every boss has an assistant to look after, to do all less important and time-consuming tasks. If a file or a cup of coffee is needed, an assistant is on the run. Some bosses barely know what’s going on in the office, so they ask their assistants regarding this too. They do some work themselves but for most other things they need the help of their assistants.
In this scenario,
Boss – is the Android application
Assistant – is a context
Files/Cup of coffee – are resources
We generally call context when we need to get information about different parts of our application like Activities, Applications, etc.
Some operations(things where the assistant is needed) where context is involved:
Different ways of getting context:
getContext()
getBaseContext()
getApplicationContext()
this