Implicit and Explicit Intent in Android Studio | Android Studio Tutorials

Implicit and Explicit Intent in Android Studio | Android Studio Tutorials

Introduction -

Intent is an messaging object which passes between components like services, content providers, activities etc. Normally startActivity() method is used for invoking any activity.

Some of the general functions of intent are:

  1. Start service
  2. Launch activity
  3. Display web page
  4. Display contact list
  5. Message broadcasting
Intent Classification

There are two types of intents

1. Implicit Intent
2. Explicit Intent

Implicit Intent: Using implicit Intent, component can’t be specifying. An action to be performed is declared by implicit intent. Then android operating system will filter out component which will response to the action.

Use implicit intent when you don't know which activity of which application/s can handle your request.

Example: You have a link. When you click the link it should open the webpage in some browser. You DON'T KNOW exactly which Activity in which application can handle your request. You just have a vague idea that its a webpage link so it should open a webpage in some browser when someone opens it. In this case, you just specify the ACTION and then OS takes care of the rest.

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));

Explicit Intent: Using explicit intent any other component can be specified. In other words, the targeted component is specified by explicit intent. So only the specified target component will be invoked.

Use explicit intent when you know exactly which Activity can handle your request.

Example: You have a List Activity and when you click an item in the list it opens a Detail activity. In this case, you KNOW that the details of the item can be shown or handled by DetailActivity.class of your application. So to perform this action you create an Intent by explicitly specifying the class name.

Intent showDeatil = new Intent(this,DetaiActivy.class);  

Post a Comment