Header Ads

What is Android Intent for, and how many types of Intent are?



Intent:

Intent is to perform an action. It is mostly used to start activity, send broadcast receiver, start services and send message between two activities. There are two intents available in android as Implicit Intents and Explicit Intents.

 

Explicit Intent − It going to connect the internal world of an application such as start activity or send data between two activities. To start new activity, we have to create Intent object and pass source activity and destination activity as shown below –

 

Intent send = new Intent(MainActivity.this, SecondActivity.class);

startActivity(send);

 

And we should declare about second activity in Manifest.xml file or else it going to show run time exception. sample declaration is as shown below.

 

<activity android:name = ".SecondActivity"></activity>

 

Implicit Intents − It going to connect without side application such as call, mail, phone, see any website etc. In implicit intent we have to pass an action using setAction() as shown below example.

 

Intent i = new Intent();

i.setAction(Intent.ACTION_VIEW);

i.setData(Uri.parse("www.ltm-web.com"));

startActivity(i);

 

No comments

Theme images by Matt Vince. Powered by Blogger.