Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 841
Adham Avatar asked Apr 22 '12 22:04

Adham


People also ask

What is the difference between activity and intent?

Activity is a UI component which you see on your screen. An Intent is a message object which is used to request an action from the same/different app component.

What are the two types of intent?

There are two intents available in android as Implicit Intents and Explicit Intents.

What is intent filter?

An intent filter declares the capabilities of its parent component — what an activity or service can do and what types of broadcasts a receiver can handle. It opens the component to receiving intents of the advertised type, while filtering out those that are not meaningful for the component.


2 Answers

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

like image 90
MichaelP Avatar answered Sep 30 '22 14:09

MichaelP


  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

like image 29
Varun Bhatia Avatar answered Sep 30 '22 15:09

Varun Bhatia