Pages Navigation Menu

Coding is much easier than you think

How To Create an Activity For Your App using Eclipse

How To Create an Activity For Your App using Eclipse

In this Tutorial, you will be Learning ,

How to create and start a new activity?

Here you go!!!!



Before creating an android application using Eclipse, let us see some of the key terms involved in this application.

Key terms involved in this project:

Activity:  An activity provides a user interface for a single screen in your application. The window typically fills the screen, but may be smaller than the screen and float on top of other windows. An application usually consists of multiple activities that are loosely bound to each other. Each time a new activity starts, the previous activity is stopped, but the system preserves the activity in a stack (the “back stack”). When a new activity starts, it is pushed onto the back stack and takes user focus.

The tutorial helps you to create your first android activity. This project is developed in Eclipse 4.2 (Juno) and tested with Android 2.2

If you are new to new to android application project, to create a new project in Eclipse refer Creation of Android Project.

Now let’s go to the coding section.


Now let’s go to the coding section. This project requires following files.

Source Code:


Activity Files:

  1. activity_createactivity.xml

res – Values:

  1. strings.xml

Manifest file:

  1. AndroidManifest.xml

Here is the coding for the above files€.

package com.simplecodestuffs.activity; // activity package
import android.os.Bundle; //A mapping from String values to various Parcelable types.
import; // Required to create an activity.
import android.view.Menu; // Interface for managing the items in a menu.
public class Createactivity extends Activity {// all classes extends activity
	protected void onCreate(Bundle savedInstanceState) {
// displays activity create activity when app starts
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(, menu);
		return true;


<LinearLayout xmlns:android=""
    android:orientation="vertical" >
        android:text="First activity success" />


<menu xmlns:android="" >



Android Manifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=""
    android:versionName="1.0" >

        android:targetSdkVersion="8" />

        android:theme="@style/AppTheme" >
            android:label="@string/app_name" >
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />



<?xml version="1.0" encoding="utf-8"?>

    <string name="app_name">Activity</string>
    <string name="menu_settings">Settings</string>




        Base application theme, dependent on API level. This theme is replaced
        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
    <style name="AppBaseTheme" parent="android:Theme.Light">
            Theme customizations available in newer API levels can go in
            res/values-vXX/styles.xml, while customizations related to
            backward-compatibility can go here.

    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->


Run the android application:

Android applications can be run on the android devices. You can either connect a hardware to the system to test the application or you can use the android virtual devices (AVD) Manager to create/manage the virtual devices running on emulator to run the application.

To run the application/ project, build your project using Project->Build Project.


This will show errors in Console window at the bottom of the working area in case your project contains any errors.

If your build is successful, Run your application using Run-> Run or Press Ctrl +F11.


Upon running the application, the emulator will be launched which displays the AVD on your screen.



To test your application, unlock the screen and double click on your app.

AVD Home screen_8

Activity success

Thus the android application project is executed successfully.


Click here to Share It..!!