Please explain every line of what it does.

Zadolbalsya already with this Intent, nicherta can not understand how it works.

Rather, I theoretically understand that intent causes other activity within an application or in other applications, explicitly or implicitly.

But how, I do not understand.

private void callSendMeMail() { Intent Email = new Intent(Intent.ACTION_SEND); Email.setType("text/email"); Email.putExtra(Intent.EXTRA_EMAIL, new String[]{"mail@mail.com" }); Email.putExtra(Intent.EXTRA_SUBJECT, "ATM_Support"); startActivity(Intent.createChooser(Email, "Отправить сообщение разработчику")); } 

    2 answers 2

    The Android system is an intermediary. Intent designed to organize the interaction between Android components using Android . You do not send a message to any application directly, you send it to the System. The system runs through the Manifestoes of all installed applications and searches for those applications that have declared the ability to perform an action that you pass as an argument to Intent , that is, Intent.ACTION_SEND - sending a message.

    Next, you specify the data type in this message - text/email . Through .putExtra you .putExtra additional information, namely, you inform what address you need to send a message ( Intent.EXTRA_EMAIL ) and subject of the message ( Intent.EXTRA_SUBJECT ).

    startActivity starts the sending mechanism. Intent.createChooser receiving the Intent collected by you, you will be offered to choose to the User the Default Application (if there are several) to send the message.

    • Good day. Please tell me why write new String [] {"mail@mail.com"} in this line: Email.putExtra (Intent.EXTRA_EMAIL, new String [] {"mail@mail.com"}); ? Can I specify after: Intent.EXTRA_EMAIL, the variable that will hold the email? - Flash Roman
    • @ FlashRoman: putExtra (...) is an overloaded method. Here is your option . Here is what you might need. - TimurVI

    First we declare that we are going to send something ( Intent is translated as intention)

     Intent Email = new Intent(Intent.ACTION_SEND); 

    Further, we say that the mime type of what we are going to send will be such

     Email.setType("text/email"); 

    Additionally, we report more parameters Intent

     Email.putExtra(Intent.EXTRA_EMAIL, new String[]{"mail@mail.com" }); Email.putExtra(Intent.EXTRA_SUBJECT, "ATM_Support"); 

    Then we inform OSi that we have such an intention, while additionally we ask ( createChooser() ) that if there are several intent handlers, then we can offer a choice.

     startActivity(Intent.createChooser(Email, "Отправить сообщение разработчику")) 

    As a result, if there are several programs in the system that send email, then a choice will be offered, if none, a warning message of the type will pop up:

    Soryan no such

    The OS determines which Activity / application to launch based on the type and action of the Intent .