Linking Activities Using Intents

An Android application can contain zero or more activities. When your application has more than one activity, you may need to navigate from one activity to another. In Android, you navigate between activities through what is known as an intent.

Today i will talk about how to navigate from your current activity to another one. We will create new android project.

Then we will add new Activity by right click on package name under src folder then choose New –> Other –> AndroidActivity, And give it a name (I will name it “Activity2”) and press finish button.

After that we should add this activity to our AndroidManifest.xml … We will add those lines

And as we said before @string used to add our program strings in one file called strings.xml .. So we will simply go to strings.xml file and add this line

Activity2 is the title of our new Activity .. or you can name it as you like 🙂

Then we go to our res –> layout –> right click –> New –> Other –> Android XML File … ( I will name it activity_activity2.xml ) … then add this code to it.

Return back again to strings.xml to add txtactivity by adding this line

We go to our first activity xml ( main.xml file ) and create a button by adding this code …

And as we do before go to strings.xml and add a text for button like this

Then go to our class to link your button in .xml with your button in .java class, and after that when button pressed we write the code that enable us to navigate to another Activity.

Run your code and enjoy 😀 .. This is the first screen

After you press the button .. The second Activity will be shown

That’s all for now, and i hope it’s easy to understand … if you have any question don’t hesitate 🙂


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s