What is the different between Explicit and implicit activity call in android?

Related searches

What is the difference between explicit and implicit activity call in android? If you explain the answer with a simple example will be good.

For example:

implicit activity call

In intent filter you create action for you activity, so other app can call your activity via this action as following:

<activity android:name=".BrowserActivitiy" android:label="@string/app_name">
   <intent-filter>
      <action android:name="android.intent.action.VIEW" />
      <category android:name="android.intent.category.DEFAULT" />
      <data android:scheme="http"/> 
   </intent-filter>
</activity>

And the other way to call implicit Intent is below:

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

Explicit activity call

You make a call that indicate exactly which activity class:

Intent intent = new Intent(this, ActivityABC.class);
intent.putExtra("Value", "This value for ActivityABC");
startActivity(intent);

Hope this help you understand more about Explicit and implicit activity call in android.

You can get more detail about Android Intent here

What is the different between Explicit and implicit activity call in , Explicit Intent: Explicit intent names the component. Implicit Intent: Implicit Intents have not specified a component. E.g: The java class which� 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. For Example

  1. Explicit Intents are used to call a specific component. When you know which component you want to launch and you do not want to give the user free control over which component to use.For example, you have an application that has 2 activities. Activity A and activity B. You want to launch activity B from activity A. In this case you define an explicit intent targeting activityB and then use it to directly call it.
  2. Implicit Intents are used when you have an idea of what you want to do, but you do not know which component should be launched. Or if you want to give the user an option to choose between a list of components to use. If these Intents are send to the Android system it searches for all components which are registered for the specific action and the data type. If only one component is found, Android starts the component directly. For example, you have an application that uses the camera to take photos. One of the features of your application is that you give the user the possibility to send the photos he has taken. You do not know what kind of application the user has that can send photos, and you also want to give the user an option to choose which external application to use if he has more than one. In this case you would not use an explicit intent. Instead you should use an implicit intent that has its action set to ACTION_SEND and its data extra set to the URI of the photo.

An explicit intent is always delivered to its target, no matter what it contains; the filter is not consulted. But an implicit intent is delivered to a component only if it can pass through one of the component's filters

Difference between implicit and explicit intents, Android | Implicit and Explicit Intents with Examples Intent is an messaging object which passes between components like services, content The startActivity() method starts to call a webpage for opening specified by the intent. Explicit Intent: Using explicit intent any other component can be specified. In this case you define an explicit intent targeting activityB and then use it to directly call it. Implicit Intents are used when you have an idea of what you want to do, but you do not know which component should be launched. Or if you want to give the user an option to choose between a list of components to use.

See Intent Resolution here

http://developer.android.com/guide/topics/intents/intents-filters.html

Explicit intents (activities) refer to a specific class, and in general, are only available to your packages. Implicit intents refer to intent filters where apps publicly announce that they can handle certain types of data or can provide specific services, e.g. send an email. With implicit intents, the users chooses which activity (typically a package) to use to handle the intent or if a default handler is set, it is launched.

Android, Explore the difference between implicit and explicit intents, how and when they are used, and the The first kind is called an explicit intent. Explicit Android: Android Explicit intent specifies the component to be invoked from the activity. In other words, we can call another activity in android by explicit intent. Implicit Android: 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.

When to use which?

Explicit intent: When you know which component can handle your request. So you explicitly mention that component name in the intent.

Intent i = new Intent(context,DetailActivity.class);  // DetailActivity.class is the component name
startActivity(i);

Implicit intent: When you don't know which application can handle your request then you mention the action in intent and let the OS decide which application/s is/are suitable for your task.

Example: Play music

Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(file);
startActivity(intent);
How OS decides?

When there is implicit call with an intent then OS takes out the action and then it matches with all the intent-filters of all the registered activities of all application using PackageManager and then populates the result as a list. It is called intent resolution So there is a possibility that no application is available in your device which can handle your request. In that case, you will get NullPointer Exception.

So a safer way to call implicit intent would be this

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(file);
if (intent.resolveActivity(getPackageManager()) != null) {
    startActivity(intent);
}

Intents and Intent Filters, Implicit vs Explicit BroadcastReceivers. Before we differentiate, let’s know the difference between Implicit and Explicit Intents. Explicit Intents are used to call a particular component that you know of. Implicit Intents are used when you don’t know the exact component to invoke. Take the example of capturing a photo from camera or gallery.

Every time I get confused among these in either interview. So, I have summarised it like this, may it help someone to keep this difference in mind.

Summary:

In Implicit Intents, the user implicitly tells the system WHAT should be done, without specifying who should do.

In Explicit Intents, the user explicitly tells the system WHOM to be triggered for whatever the work is.

Explicit and implicit intents, Android Explicit intent specifies the component to be invoked from activity. In other words, we can call another activity in android by explicit intent. We can also pass the information from one activity to another using explicit intent. Here, we are going to see an example to call one activity from another and vice-versa. Android calling one

If you look at implicit and explicit closely, you will understand that they have different purposes. If you take a look at this word in the linguistical point of view, you will see that implicit is used as an adjective while explicit is used as an adjective as well as a noun. The origin of implicit is found in the late 16th century.

A good way to keep explicit vs implicit apart is to remember that Implicit is an Implied or Indirect statement. Both of these start with the letter “I.” Explicit starts with an “E” and is Spelled Out, so there is no confusion. Summary. Implicit and explicit have near opposite meanings, so it’s important to remember their difference.

Comments
  • Related thread - Android implicit intents VS explicit intents