Android Start New Activity Example

Learn About Android Start New Activity Example

Here we will learn about Android Start New Activity Example.  This is the simplest way to start a new activity in android. First we will create  a new Android Activity and then start a new android activity from another Activity. Also we can start a new android activity from any other components (like from Android Services, Button click etc). To make the example very clear, We will create a new activity and start the activity from another activity’s button click event. We can also find the complete code description here.

Android Start New Activity Example Screen Shots

android-start-new-activity  android-new-activity

Android Code Snippet to Start a new Activity

That’s it. In the above code snippet Android Activity Manager will start your requested Activity. If your Activity code if ready, then you can put the above code snippet in your code from where you want to start a Activity. Please make sure to replace the Activity name (TestActivity) with your Activity name from the above code snippet. Also make sure to add your Activity’s name in your app’s Manifest file. If you are still facing any issue then don’t worry below you can download complete code with description.

Android Start New Activity Example Details

In the Application we will create 2 Android Activities. One will have a simple button from where we will start the new Activity. For an Android Activity, we need two parts (One is the xml layout file and other is the Activity code logic in the java file). So let’s start.

1. Layout xml File (activity_main.xml) for MainActivity

This xml layout file will be used for showing GUI for our MainActivity, So we have added below GUI options in this xml layout file.

1. One a Android TextView (for showing simple information). The text view is optional.

2. One Android Button (we will start the new activity from this button click option)

2. Layout xml File (activity_test.xml) for New Activity

This simple xml layout file will be used for showing GUI for our new Activity, which will be start from the main Activity. Here we have added one simple TextView to show some information on the new Activity.

 3. MainActivity.Java File

This activity is the main activity from where we will start the new activity.

 4. TestActivity.Java

This simple java file contains the code for your new Activity, which we are going to launch from the MainActivity.

 5. Manifest File

We need to add each android Activity name in this file, which we are using in our application. So Below is the Manifest file in which we have added (both MainActivity and TestActivity ) names.

Note: If you will forget to add your Activity name in the Manifest file, then Android will not found it in the package and will show Force Close Error, when you will run the application.

That’s it, you can file source code specific comments and description, once you will download and run the code on Emulator or Device.

Download Android Start New Activity Example Source

downloadDownload Android Start New Activity Example Source Code from Here.

I hope This small tutorial will help you at it’s best.


Post By SmrutiRanjan (57 Posts)

Working @ Samsung as a Project Lead for Android Smartphones. I have been blogging since 2008. Previously I was writing articles for other bloggers, but finally I have started my own blog-"Techblogon".I am also an active contributor for the blog-"Gadgets n Gizmos World". Job is my necessity, but blogging is my passion.

Website: → Techblogon


7 Responses to Android Start New Activity Example

  1. Manmaya Champatiray says:

    It’s a nice blog for the android beginners…
    But plz rectify the .XML file name
    i.e activity_text.xml to activity_test.xml

  2. MOHANRAJ says:

    hello sir,
    android:onClick=”newActivityOnClik”/>. is these lines created automatically or we should add it?

  3. full says:

    why my error is this?
    getMenuInflater().inflate(, menu);

    the activity_main is red underline?
    i only copy your tutorial and makes me wrong but when i download your project it is working

    help thanks in advance

  4. stefanbanu says:

    hi, i have a question, how can i put a button on the activity_test layout, and when i push that button to bring me again to the main activity?

Leave a Reply

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

− six = 3

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">