Android Intent |Android App Development With AndroidCource

Thursday 14 September 2017

Android Intent

What is Intent ?


Android Intent is the message that is passed between components such as activities, content providers, broadcast receivers, services etc.

It can be used with startActivity to launch an Activity, broadcastIntent to send it to any interested BroadcastReceiver components, and startService(Intent) or bindService(Intent, ServiceConnection, int) to communicate with a background Service.

There are separate mechanisms for delivering intents to each type of component − activities, services, and broadcast receivers.

startActivity()

The Intent object is passed to this method to launch a new activity or get an existing activity to do something new.

startService()

The Intent object is passed to this method to initiate a service or deliver new instructions to an ongoing service.

sendBroadcast()

The Intent object is passed to this method to deliver the message to all interested broadcast receivers.

Intent Objects

An Intent object is a bundle of information which is used by the component that receives the intent as well as information used by the Android system.

Types of Intents

Implicit Intent

Implicit Intent doesn't specifiy the component.intent provides information of available components provided by the system that is to be invoked.

Example

            Intent intent=new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse("http://www.google.com"));
            startActivity(intent);


Explicit Intent

Explicit Intent specifies the component.intent provides the external class to be invoked.

Example

            Intent i = new Intent(getApplicationContext(), ActivityTwo.class);
            startActivity(i);


0 comments:

Post a Comment