Saturday, November 12, 2016

Intents in android

Android Intent is the message that is passed between components such as activities, content providers, broadcast receivers, services etc.
It is used with startActivity() method to invoke activity, broadcast receiver etc.
Android intents are mainly used to:
Start the service
Launch an activity
Display a web page
Display a list of contacts
Broadcast a message
Dial a phone call etc.
Types of Android Intents
There are two types of intents in android: implicit and explicit.
1) Implicit Intent

Implicit Intent doesn't specifiy the component. In such case, intent provides information of available components provided by the system that is to be invoked.
For example, you may write the following code to view the webpage.
Intent intent=new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://www.javatpoint.com"));
startActivity(intent);

2) Explicit Intent

Explicit Intent specifies the component. In such case, intent provides the external class to be invoked.

Intent i = new Intent(getApplicationContext(), ActivityTwo.class);
startActivity(i);
To get the full code of explicit intent, visit the next page.