---
title: "What is Context in Android?"  
description: "What is Context in Android?"  
author: "Samuel Fernandes"  
published: 2015-05-20  
updated: 2015-05-20  
canonical: https://www.mindstick.com/forum/23245/what-is-context-in-android  
category: "android"  
tags: ["android"]  
reading_time: 2 minutes  

---

# What is Context in Android?

In [Android](https://www.mindstick.com/articles/13046/10-reasons-why-i-prefer-android-vs-iphone-ios) [programming](https://www.mindstick.com/articles/12214/web-development-company-in-india-laid-on-the-foundation-of-concrete-java-programming), what exactly is a [Context](https://www.mindstick.com/forum/12899/how-can-i-extend-an-api-controller-to-hold-a-variable-for-my-database-context) [class](https://www.mindstick.com/blog/165/generic-class-in-c-sharp) and what is it used for? I read about it on the [developer](https://www.mindstick.com/articles/157260/variation-between-web-designer-and-web-developer) site, but I [am unable](https://answers.mindstick.com/qa/95314/how-do-i-access-a-group-link-in-telegram-if-i-am-unable-to-access-the-link) to understand it clearly.

## Replies

### Reply by Anonymous User

**Concept:**

- It's like access of android-activity to app's resource
- It's similar to a when you visit a hotel, you want breakfast, lunch & dinner in suitable timings right?
- There are many other things you like during the time of stay. How you get these things?
- You ask the room-service person to bring the things for you
- Here room-service person is the context considering you are the single activity and the hotel to be your app, finally the breakfast, lunch & dinner to be the resources

As the name suggests, its the context of current state of the application/object. It lets newly created objects understand what has been going on. Typically you call it to get information regarding another part of your program (activity, package/application)\
You can get the context by invoking getApplicationContext(), getContext(), getBaseContext() or this (when in the activity class).\
**Typical uses of context:**\
Creating New objects: Creating new views, adapters, listeners:

```
TextView tv = new TextView(getContext());ListAdapter adapter = new SimpleCursorAdapter(getApplicationContext(), ...);
```

Accessing Standard Common Resources: Services like LAYOUT_INFLATER_SERVICE, SharedPreferences:

```
context.getSystemService(LAYOUT_INFLATER_SERVICE)   getApplicationContext().getSharedPreferences(*name*, *mode*);
```

Accessing Components Implicitly: Regarding content providers, broadcasts, intent

```
getApplicationContext().getContentResolver().query(uri, ...);
```


---

Original Source: https://www.mindstick.com/forum/23245/what-is-context-in-android

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
