Day 5 : Playing with Activities in Android and Passing Data between Them

1 min read

Dear Friends

First of all Thanks for providing me this opportunity to teach you. Today we gonna play with different two of more different activities. So at last we will be having an android application where different activities interact with each other and do some creative things.

Lets have an Activity A and activity B in application.  Now how to create a simple application and activity you can have a look at my blog post.

So now there are two activities in our application. lets have a method called startB() in Activity A . This method will start activity B on our request. Below is the pseudo code how this method will look like

public void startB() {

Intent startBIntent = new Intent(A.this,B.class);




Now to understand above code lets go line by line. First line inside method startB() .. there is an Object called Intent is used. So what is intent. Intent is sort of messages those are running around in the system.

Uses :

So if it is two activities and they need to pass some data between each other , intents are used.  There can be multiple combination of activties , broadcast receivers , services those interact with each other via intent.

Now if you see the above code Intent’s constructor takes two arguments Context and Class which is to be invoked.

After that we just startActivity using intent that we created. On device first Activity A is shown . on the call of startB method Activity B  would be launched. So now you app is having two different activities which can interact with other.



Create an android application where we need to Pass some primitive data between two activities via intent.


Happy Coding !




Leave a Reply

Your email address will not be published. Required fields are marked *