

package name, which identifies the application that contains the component.When explicitly starting a component, two pieces of information are required: Val intent = Intent ( context, MyActivity :: class.

class ) startActivity ( intent ) // Provide context if MyActivity is an internal activity. Intent intent = new Intent ( context, MyActivity. Explicitly starting a component // Provide context if MyActivity is an internal activity. What is a Context used for?īelow are a few use cases that require a Context object. In situations where we are outside of an activity (in an application or service), we can use the "application" context instead. In situations where we are inside objects created by the activity such as adapters or fragments, we need to pass in the activity instance into those objects. In many cases when the "context is required", we simply need to pass in the instance of the current activity.

It also enables access to Android's built-in services, such as those used for layout inflation, keyboard, and finding content providers. It provides Activities, Fragments, and Services access to resource files, images, themes/styles, and external directory locations. A Context provides access to information about the application state.
