What is 'Context' on Android?

前端 未结 30 2909
南旧
南旧 2020-11-21 04:46

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

30条回答
  •  北海茫月
    2020-11-21 05:21

    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.

提交回复
热议问题