
sendBroadcast ( broadcastIntent ) Retrieving a System Service Val broadcastIntent = Intent ( "custom-action" ) LocalBroadcastManager. which manages the queue for the application's main thread. sendBroadcast ( broadcastIntent ) // The context contains a reference to the main Looper, Intent broadcastIntent = new Intent ( "custom-action" ) LocalBroadcastManager. We use the context to fetch the LocalBroadcastManager when sending out or registering a receiver for a broadcast: // The context contains a reference to the main Looper, // which manages the queue for the application's main thread. my_layout, parent ) Sending a local broadcast my_layout, parent ) // A context is required when creating views. LayoutInflater inflater = LayoutInflater. We use the context to fetch the LayoutInflater in order to inflate an XML layout into memory: // A context is required when creating views.


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.
