Hi guys, Welcome to our Fifth Tutorial for Android Application Development. In our last Tutorial we designed a Caller Application using Hybrid Approach and learnt about basic concepts of Intent in Android. Today we’ll be designing a Multi-Activity App using Intent which will allow us to jump between two different activities.

As explained in our Fourth Tutorial, Intent In Android is just a message passed in communication between Applications. Before moving any further, let’s learn a few things that will be required while designing a Multi-Activity Application.

First, What is an Activity?

Activity is a Java code that supports a screen or UI. In simpler words, Activity is just like a Page for the user!

Activity is also a predefined class in Android and every application which has UI must inherit it,in order to create a window. So, we can imply that an Activity is a combination of the Java Code and XML.(Android Docs)
In our today’s Tutorial we’ll be designing an Application containing two Activities. With every new activity created, we must specify it inside our AndroidManifest.xml file as well. Let’s take a look on how to do that!

Activity Declaration In AndroidManifest.xml

Every time we create an Activity, it’s necessary to Register it inside our AndroidManifest.xml file. This is how we do it!
Inside the tags add another tag using the following format :

    android:name = “packagename.activityname”
    android:label = “@string/app_name”

Okay! So we’re done with Registering our Activity inside our AndroidManifest.xml file.

We’ll design our Multi-Activity Application in such a way that we enter some data, say Name and Phone Number in first Activity, and display that data on the Second Activity. But for that we must know how to Receive and Send data between two different Activities Using Intent!

Receiving Data from Send Intent

In our last Tutorial we saw how Intent works, using Action and URI. 
In today’s tutorial, we will learn how to Pass data between two different activities. Well for passing data between two activities, we should know how to Send and Receive the data.

We’ll be using a static function putExtra() with the following format to send values :
IntentName.putExtra(“key”, value)
The “key” value is the unique identifier through which the value is accepted at the receiving end!

For receiving the value we use a function getIntent() that automatically creates an object of type intent using which we access the getStringExtra() function. Format for receiving values using Intent :

So this is all we need to know for creating a Multi-Activity Application using Intent In Android!


Following are the steps to Create a Multi-Activity App using Hybrid Approach :

  • Create a New Android Application Project.
  • We’ll be creating two java files(FirstActivity.java & SecondActivity.java), and two Xml(activity_first & activity_second) files



Graphical Layout

Android 101 - Day 4 - Intent In Android


package bitsnapper.multiapp;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import android.os.Build;

public class FirstActivity extends ActionBarActivity implements OnClickListener {

	EditText et1, et2;
	Button b1;

	protected void onCreate(Bundle savedInstanceState) {
		et1 = (EditText) findViewById(R.id.editText1);
		et2 = (EditText) findViewById(R.id.editText2);
		b1 = (Button) findViewById(R.id.button_next);

	public void onClick(View arg0) {
		// TODO Auto-generated method stub

		String name = et1.getText().toString();
		String number = et2.getText().toString();

		// if values are not entered, we display a toast
		if (name.equals("") || number.equals("")) {
			Toast.makeText(this, "Please enter the values", Toast.LENGTH_SHORT).show();
		} else {
			Intent next = new Intent(this, SecondActivity.class); // We initialize an Intent named next
			next.putExtra("NAME", name);
			next.putExtra("NUMBER", number);
			startActivity(next); //This function executes the intent and transfers the control to SecondActivity.java
			finish(); //This destroys the FirstActivity once the control is transferred.


To create a new xml file :

  • Right Click on Layout directory > New > Android XML file 
  • Enter name and select the Type of Layout and click on Finish.



Graphical Layout

Android 101 - Day 4  Intent In Android


To create a new java file :

  • Right Click on PackageName > New > Class 
  • Enter name of your New class and click on Finish.
package bitsnapper.multiapp;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class SecondActivity extends Activity implements OnClickListener {

	TextView tv1, tv2;
	Button b1, b2;

	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub

		tv1 = (TextView) findViewById(R.id.textView1);
		tv2 = (TextView) findViewById(R.id.textView2);

		b1 = (Button) findViewById(R.id.button_main);
		b2 = (Button) findViewById(R.id.button_exit);


		Intent receive = getIntent();
		// Receiving Values using keys
		String name = receive.getStringExtra("NAME");
		String number = receive.getStringExtra("NUMBER");


	public void onClick(View v) {
		// TODO Auto-generated method stub

		switch (v.getId()) {

			case R.id.button_main:
				Intent main = new Intent(this, FirstActivity.class);
				startActivity(main); // Will transfer the control to Main screen


			case R.id.button_exit:




Multi-Activity Application – Demo

Our Multi-Activity Application consists of the following two pages displayed below :-

#1 First Page : Here we will enter the values in the Name and Number Fields.

Android 101 - Intent In  Android

#2 Second Page : The values entered in the first page are displayed here!

Android 101 - Intent in Abdroid

So, as you can see our Multi-Activity Application is running successfully. We’ll design more complex applications in our upcoming tutorials that will use the Concept of Intent In Android! So make sure you get all your Concepts clear. Any queries regarding the Content or Concept of Intent in particular are welcome!

Multi-Activity Application – Source Code

• Multi-Activity Application – Download

That’s all for our fifth tutorial. In our next tutorial, we will learn the concept of Server Sockets in Android and design a simple application to send and receive a message on your device! So stay tuned and in the meanwhile, build something innovative using the concept above and surprise us. Cheers 😎