Understanding Context by a Real World Example

Let’s a person visit a hotel. He needs breakfast, lunch, and dinner at a suitable time. Except for these things there are also many other things, he wants to do during his time of stay. So how does he get these things? He will ask the room-service person to bring these things for him. Right? So here the room-service person is the Context considering you are the single activity and the hotel to be your app, finally, the breakfast, lunch & dinner have to be the resources.

What is Context in Android?

Android Applications are popular for a long time and it is evolving to a greater level as users’ expectations are that they need to view the data that they want in an easier smoother view. Hence, the android developers must know the important terminologies before developing the app. In Android Programming we generally come across the word Context. So what exactly is this Context and why is it so important? To answer this question let’s first see what the literal meaning of Context is:

The Circumstances that form the setting for an Event, Statement, or Idea, and in terms of which it can be fully understood.

Looking at this definition we come across two things:

  • The Context tells us about the surrounding information.
  • It is very important to understand the environment which we want to understand.

Similarly when we talk about Android Programming Context can be understood as something which gives us the Context of the current state of our application. We can break the Context and its use into three major points: 

  • It allows us to access resources.
  • It allows us to interact with other Android components by sending messages.
  • It gives you information about your app environment.

The code has been given in both Java and Kotlin Programming Language for Android.

Similar Reads

Understanding Context by a Real World Example

Let’s a person visit a hotel. He needs breakfast, lunch, and dinner at a suitable time. Except for these things there are also many other things, he wants to do during his time of stay. So how does he get these things? He will ask the room-service person to bring these things for him. Right? So here the room-service person is the Context considering you are the single activity and the hotel to be your app, finally, the breakfast, lunch & dinner have to be the resources....

How Does this Work?

1. It is the Context of the current/active state of the application....

Types of Context in Android

There are mainly two types of Context that are available in Android....

Contact Us