How to start an activity from another activity in Android


In our blog today you will learn to create a new activity from another activity. We have the main activity called as “”. It will call two activities namely “” and “”. ChildActivity is a simple activity that just displays a message. “second_child” demonstrates the method of passing values to activities by calling another activity “”. The result from “” is passed onto Let us start writing the code

Step 1

Create an Android Project and name it “StartNewActivity”. Select the Android SDK version of your choice. Once the project gets created open the “” and write the code below

Update the main.xml files as follows

Step 2

Create “” under src folder and add the following

Step 3

Update the child_Layout.xml with the following

Step 4

Create and update the and second_child.xml

Step 5

Create and update the and second_child_result.xml

Step 6

Make sure your Android manifest file looks like the following

You are now ready to compile and execute the code. The output will look like the following