What is 'Context' on Android?

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

    • Context represents a handle to get environment data .
    • Context class itself is declared as abstract, whose implementation is provided by the android OS.
    • Context is like remote of a TV & channel's in the television are resources, services, etc.

    What can you do with it ?

    • Loading resource.
    • Launching a new activity.
    • Creating views.
    • Obtaining system service.

    Ways to get context :

    • getApplicationContext()
    • getContext()
    • getBaseContext()

提交回复
热议问题