What is 'Context' on Android?

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

    Context is context of current state of the application/object.Its an entity that represents various environment data . Context helps the current activity to interact with out side android environment like local files, databases, class loaders associated to the environment, services including system-level services, and more.

    A Context is a handle to the system . It provides services like resolving resources, obtaining access to databases and preferences, and so on. An android app has activities. It’s like a handle to the environment your application is currently running in. The activity object inherits the Context object.

    Different invoking methods by which you can get context 1. getApplicationContext(), 2. getContext(), 3. getBaseContext() 4. or this (when in the activity class).

提交回复
热议问题