Android Intents

Android Intents

A simple tutorial to understand the working of intents

Subscribe to my newsletter and never miss my upcoming articles

An Intent in andorid application provides runtime binding between seprate components of android applications.

You can use intents to move from one activity of app to other activity of app, You can use intents to move data from one activity of app to other and you can also call other applications using intent to perform some task for you.

Intent intent = new Intent(MainActivity.this, AnotherActivity.class);
startActivity(intent); // startActivity allow you to move

Intent to Move from one activity to other with Data

  • message_text is the EditText in this example.

  • string abc is the simple string in this example

  • int a is just an integer in the example

        message_text = (EditText) findViewById(;  
        String message = message_text.getText().toString();  
        String abc = "This is the string value";
        Int a = 20;
        Intent intent= new Intent(this ,SecondActivity.class);  
        intent.putExtra("StringAbc", abc);
        intent.putExtra("intValue", a);  

How to extract the data in SecondActivity sended by FirstActivity

protected void onCreate(Bundle savedInstanceState) {
    //Get the Intent that started this activity and extract the string
    Intent intent = getIntent();
    String message = intent.getStringExtra("MessageNumber1");
    String abc = intent.getStringExtra("StringAbc");
    Int a = intent.getIntExtra("intValue",0);
    //Note the 0 at the end is a default value if the number sent is empty.

Intents with ACTION_SEND When we use the intents with action send we don't know who will recieve the data it is upto user, The user chose the other app where He want to send the data.

Picture below is the example of it.

Untitled.png Here is the code to make this kind of Intent in Java

btn_Share = findViewById(;
TextView_QuoteNumber = findViewById(;
textView_Quote = findViewById(;

final String Quote = textView_Quote.getText().toString();
String QuoteNumber = TextView_QuoteNumber.getText().toString();

btn_Share.setOnClickListener(new View.OnClickListener()
            public void onClick(View view) {
            Intent sendintent = new Intent();
            sendintent.putExtra(Intent.EXTRA_TEXT, Quote);

The code above is binding some views of the interface into java and on button click putting data from the view into the intent and startig the activity with intent which will initiate the screen as shown above in SS.

Share this