DEV Community

Cover image for ANDROID : IMPLICIT INTENT
DevByJESUS
DevByJESUS

Posted on

ANDROID : IMPLICIT INTENT

Before dive into the core subject of this post , we should know what is an intent in android development , what are the differents types of intent , and finally talk deeply about the type focus in this post. let's go 😇

1. WHAT IS AN INTENT IN ANDROID DEVELOPMENT

An intent in android development is a function that permits to go from one activity to another , or for those who do not know to go from one view to another , but this is the simplest definition for me .
look at the image below

image

Example how to do that in your code

// create an intant to go from NoteList view to Note view
Intent goToNoteActivity = new Intent(NoteListActivity.this,NoteActivity.class);


// start the view where we want to go 
startActivity(goToNoteActivity);

Enter fullscreen mode Exit fullscreen mode

2. DIFFERENTS TYPES OF INTENT

  • 2.1 - EXPLICIT INTENT
    Is like the one below at the top , explicit simply because here we specify to the Intent , the departure view and the arrival view .

  • 2.2 - IMPLICIT INTENT
    He is here also and we can see his benefits everyday by using whatsapp or whatever social media when for example we want to take a photo through whatsapp , see the image below , later we are going to discuss his main characteristics.

image

3. THE IMPLICIT INTENT

we firstly are going to talk about the caharacteristics and after we will better understand why this word IMPLICIT

  • 3.1 - Characteristics of an implicit Intent it is described by four characteristics ( that i know 😆 at this time ) firstly we should create our intent . Intent sendIntent = new Intent();

A- Action
the action string to be implemented by the receiver , it is the only required characteristic.
sometimes specified in the constructor y default , the only required characteristic.
command below

sendIntent.setAction(ACTION);

B- Category
We do no longer need to specify it sometimes our Android System just need to know the action and according to the app on our system , the future receiver ( or app ) of the intent will perform the Action specified .

C- Data
It is the data to be shared during the exchange between the intent sender and the intent receiver .
specified with the command below .

sendIntent.setData(URI);

D- Mime-Type
Here simply the mime-type specific for the receiver of the intent to take action on the data . See the command below to done it.

sendIntent.setType(MIME_TYPE);

NB : Before i show you the example , i want to tell you that there is a function to specify both Data and Type characteristics.With the command below .

Intent.setDataAndType();

And now a minimalistic example

Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.setType("text/plain");

// it is better to make a try Catch block 
// to prevent exception
try {
    startActivity(sendIntent);
} catch (ActivityNotFoundException e) {
    // Define what your app should do if no activity can handle the intent.
}

Enter fullscreen mode Exit fullscreen mode

NB : the startActivity() takes in parameter an intent to display the receiver view ( we will discuss it in another post )

  • 3.2 So now , Why this prefix IMPLICIT

Because here like you have seen , we do not specify the receiver of that intent , just the ACTION and the system is going to find the only one or the differents app on ur android device which can perform this action .

4. LINKS

Because it is always better to go check the documentation
documentation

common intents

I have also some repositories where i have done android animations go check my github

my github link

thinking this post is going to help someone 😊

Top comments (0)