An activity in Android is a component that provides a screen with which users can interact to do something, such as dial the phone, take a photo, or view a map. It is like a window or frame of a desktop application. XML files provide the design of the screen and JAVA files deal with all coding stuff like handles, what is happening, design files, etc. JAVA files and XML files make your activity complete.

For example, when you open an app on your phone, you are interacting with an activity. When you click on a button or type something in a text box, you are interacting with that activity.

Untitled

Each activity is bundled in a Context and only the application user have access to these Context. Therefore malicious apps couldn’t access to other apps activity information because they don’t have access to their Context.

<aside> 💡 We have some scenario that developer want to make an activity able to open by 3third party application. In this case he/she can make specific activity exportable.

</aside>

What is Context?

Think of an activity as a screen in your Android app. Each activity needs some information about the app to function properly. Things like:

The context provides this information to the activity. It's like a backpack that the activity carries around, full of everything it needs to do its work.

Without a context, an activity wouldn't have access to these resources and wouldn't work properly. So every activity has a context associated with it that contains this useful information about the app.

Imagine you are in a big city, and you want to go somewhere. You need some information about the city, such as the map, the traffic, the weather, the public transportation, etc. This information is like the context of the city. It helps you navigate and interact with the city.

Now, imagine you are in a specific place in the city, such as a museum, a park, a restaurant, etc. This place is like an activity in Android. It has its own appearance and functionality. You can see things, touch things, do things, etc. But you still need the context of the city to get there and leave there. You can also use the context of the city to access other services or resources that are not part of the place itself.

So, in summary, context is a way of accessing information and resources that are related to your app environment. Activity is a way of presenting a user interface and handling user interaction within your app. Activity is a subclass of context, which means it inherits all the methods and properties of context, but it also has its own features and behaviors.

Most commonly, the context is used to: