Context is a global data about an application environment. This is an abstract class whose implementation is provided by the Android system. It allows access to application-specific resources and classes, as well as up-calls for application-level operations such as launching activities, broadcasting and receiving intents, etc
1. Application context
2.Activity context
Application context
It is application and we present in Application. Application context is the instance/object of Application. example MyApplication
It is accessed in Activity via getApplicationContext(). this context is tied to the lifecycle of application . It can be used when you need a context whose lifecycle is separate from the current context or you are passing the context beyond the scope of activity.
Activity context
It is activity and we present in Activity. Activity context is the instance/object of Activity. example MainActivity.
It is present in Activity. this context is tied to the lifecycle of activity . It can be used when you need a context whose lifecycle is attached to the current context or you are passing the context in the scope of activity.
,
0 Comments