What is 'Context' on Android?

前端 未结 30 2908
南旧
南旧 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:08

    An Android Context is an Interface (in the general sense, not in the Java sense; in Java, Context is actually an abstract class!) that allows access to application specific resources and class and information about application environment.

    If your android app was a web app, your context would be something similar to ServletContext (I am not making an exact comparison here).

    Your activities and services also extend Context, so they inherit all those methods to access the environment information in which the app is running.

提交回复
热议问题