In this article we are learning about the intent and types of intent in android.
An intent is to perform an action on the screen. Intent is used to start an activity, send a broadcast receiver, start services and send messages between two activities. Intent is used with startActivity() method to call activity, broadcast receivers etc.
Types of intent:
There are two types of intent :
- Implicit intents doesn’t specify the component, but declare a general action to perform, which allows a component from another app to handle it .In short this type of intent use for perform a action from your app to another app. For example, if you want to show the user a location on a map, you can use an implicit intent to request another capable app to show a specified location on a map.
For example, you may write the following code to view the webpage.
Intent intent=new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("https://www.thecodehubs.com/")); startActivity(intent);
- Explicit intents specify which application will satisfy the intent, by supplying either the target app’s package name or a fully-qualified component class name. You typically use an explicit intent to start a component in your own app, because you know the class name of the activity or service you want to start. For example, you start a new activity within your app in response to a user action, or start a service to download a file in the background.
Intent i = new Intent(getApplicationContext(), ActivityTwo.class); startActivity(i);
Which intent is used for what it is shortly given in the below given image :