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
What's Context
exactly?
Per the Android reference documentation, it's an entity that represents various environment data. It provides access to local files, databases, class loaders associated to the environment, services (including system-level services), and more. Throughout this book, and in your day-to-day coding with Android, you'll see the Context passed around frequently.
From the "Android in Practice" book, p. 60.
Several Android APIs require a Context
as parameter
If you look through the various Android APIs, you’ll
notice that many of them take an android.content.Context
object as a
parameter. You’ll also see that an Activity or a Service is usually used as a
Context
. This works because both of these classes extend from Context
.