Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android implicit intents VS explicit intents

Working with android I realized that implicit intents are good choice in most of cases due to their's flexibility. But what's about explicit intents? What are benefits of using them? What are common cases when it's a good practice to use them?

like image 416
Alexander Oleynikov Avatar asked May 26 '10 16:05

Alexander Oleynikov


People also ask

What are the two types of intents in android?

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

What is not specified by 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.

What are the different types of intent?

Android supports two types of intents: explicit and implicit. When an application defines its target component in an intent, that it is an explicit intent. When the application does not name a target component, that it is an implicit intent.


1 Answers

Implicit Intents do not directly specify the Android components which should be called, it only specifies action to be performed. A Uri can be used with the implicit intent to specify the data type.

for example

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

this will cause web browser to open a webpage. Android system searches for all components which are registered for the specific action and the data type.If many components are found then the user can select which component to use..

Explicit intents are used in the application itself wherein one activity can switch to other activity...Example Intent intent = new Intent(this,Target.class); this causes switching of activity from current context to the target activity. Explicit Intents can also be used to pass data to other activity using putExtra method and retrieved by target activity by getIntent().getExtras() methods.

Hope this helped.

like image 165
Aditya Kamath Avatar answered Oct 22 '22 22:10

Aditya Kamath