What is Context in android ?

 What is Context in android ? 

This is an abstract class inherited from Object class. It is implemented by the Android system to provide the information about application environment and access resources.

    Few important points about the context:
  • It is the context of the current state of the application.
  • It can be used to get information regarding the activity and application.
  • It can be used to get access to resources, databases, and shared preferences, and etc.
    There are mainly two types of context:

     -  Application Context:  It is initialised when the app is launched and resides until the app is                                                                         closed. Any resources initialised with applicationContext  will remain until                                                             the app is closed.

     -  Activity Context: It is initialised when an Activity is launched. Every activity has its own                                                                   context and will stay alive until the Activity is closed. We can use  baseContext to                                               access the context of an activity.

    

Comments