1728 views 0 comments

Android 101 : Day 4 | Intent In Android

by on August 11, 2015

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 :

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



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.


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 😎

Be the first to comment!
Leave a reply »


Leave a Reply