Intent in Android With Example And Types




Android uses Intent for communicating between the components of an Application and also from one
application to another application.
Intent are the objects which is used in android for passing the information among Activities in an
Application and from one app to another also. Intent are used for communicating between the
Application components and it also provides the connectivity between two apps.
Types of Intents:
Intent are of two types: 
  • Explicit Intent 
  • implicit intent
Explicit Intent:
Explicit Intents are used to connect the application internally.
In Explicit we use the name of component which will be affected by Intent. For Example: If we know
class name then we can navigate the app from One Activity to another activity using Intent. In the
similar way we can start a service to download a file in background process.

Explicit Intent work internally within an application to perform navigation and data transfer.
The below given code snippet will help you understand the concept of Explicit Intents
Intent intent = new Intent(getApplicationContext(), SecondActivity.class);
startActivity(intent);
Implicit Intent:

In Implicit Intents we do need to specify the name of the component. We just specify the Action which has
to be performed and further this action is handled by the component of another application.

The basic example of implicit Intent is to open any web page.


Intent intentObj = new Intent(Intent.ACTION_VIEW);
intentObj.setData(Uri.parse("https://www.codewithandroid.com"));
startActivity(intentObj);



Post a Comment

0 Comments