Install the Eclipse ADT Bundle. After unpacking, try to start the included Eclipse. You might need to install a current Java JDK. Also start the included SDK Manager and install / update packages you might need. Be prepared to wait some time here ... Building Your First App.

In the SDK Manager, Create an AVD And try to start it. You might face the problem that the start takes ages and the AVD (which simulates an Android device) is very slow. One workarround for windows computers with an Intel CPU is to install in the Android SDK Manager the "Intel x86 Emulator Accelerator (HAXM installer) and emulate an Intel Android device instead of the normal ARM one. After the installation of the HAXM installer you need to run this installer manualy once otherweise you will get this error while trying to start an Intel device:

emulator: ERROR: x86 emulation currently requires hardware acceleration!
Please ensure Intel HAXM is properly installed and usable.
CPU acceleration status: HAX kernel module is not installed!
This installer may again fail with this error message:

This computer meets the requirements for HAXM, but Intel Execute Disable Bit (XD) is not turned on. HAXM can be installed, but will not work until  XD is enabled.
Please refer to the Intel HAXM documentation for more information.

In this case try to run this (as Administrator!)

bcdedit /set nx AlwaysOn

Reboot, start the HAXM installer again. If it fails with a memory related error, assign the AVD less memory than you allowed during the HAXM installation.

However, this is still slower and less realistic than a real device, so it might be prefereable to let Eclipse run your app on a real device. Just enable USB debugging on a device and connect it via an USB cable


In the file res/values/strings.xml you will find Strings which you can reference for example in the activity_main.xml. This is an exmaple for such a file

<?xml version="1.0" encoding="utf-8"?>
    <string name="app_name">ThorstensFirstAndroidApp</string>
    <string name="hello_world">Hello world!</string>
    <string name="action_settings">Settings</string>
    <string name="edit_message">Type your value here</string>

You can provide different languages just by creating values folders for each language, e.g. values-es, values-de, values-fr, ...


A ViewGroup holds one or more ViewGroup or one or more View. An examples for a ViewGroup are the LinearLayout or the RelativeLayout

In your project in the res/layout folder there is a file called activity_main.xml which holds the layout. If a View or a ViewGroup element should be inside another, you write it inside its XML tag. You need to make sure that all Strings on OnClick methods exist in the strings.xml / the as a method. Example for an Layout:

<RelativeLayout xmlns:android=""
   tools:context="com.example.thorstensfirstandroidapp.MainActivity" >

       android:text="@string/hello_world" />

       android:hint="@string/edit_message" />

       android:text="@string/button_send" />


Your layout is scaled automatically for larger or smaller screens and it rotates also automatically if the screen is rotated. You may however also choose to to provide a complete different layout for larger screens or for screens currently in landscape rotation. Just create next to the layout folder one called for example


For a larger device in landscape mode. If you need finer control check Designing for Multiple Screens


You may also create parts of the layout via program code. See Building a Dynamic UI with Fragments


You start with the MainActivity. This is where your program starts and where buttons with onClick are searching for methods to execute. Our button expects for example a method called heyYouHitTheButton. This might be one:

public final static String MY_EXTRA_MESSAGE = "de.tgunkel.thorstensfirstandroidapp.MESSAGE";

public void heyYouHitTheButton(View view)
 // extract the value of the message the User entered before hitting the button
 EditText editText = (EditText) findViewById(;
 String message = editText.getText().toString();

 Intent intent = new Intent(this, MyFirstAndroidActivity.class);
 intent.putExtra(MY_EXTRA_MESSAGE, message);

Our method creates and Intent (see below) which starts a new Activity and passes some extra information to it.

Create a new Activity: In Eclipse New, Others, Android, New Activity The Hierarchical Parent is either the MainActivity or one of your other Activities.

In our Activity we just display the text we got via the Intent which started us and display it

public class MyFirstAndroidActivity extends Activity

    protected void onCreate(Bundle savedInstanceState)

        // get the message we did send us from the MainActivity class
        Intent intent = getIntent();
        String message = intent.getStringExtra(MainActivity.MY_EXTRA_MESSAGE);

        // Create the text view
        TextView textView = new TextView(this);

        // Set the text view as the activity layout

For further details about the different methods in an Activity and its lifecycle.


Each Activity is started by an Intent. You may explicitly start a specific Activity or you may ask the system to start any Activity which provides some service, e.g. make a phone call, take a picture or show a map. You (as the developer) do not care which app it will be. Example to show a map: intent sending

Uri location = Uri.parse("geo:0,0?q=+Deutscher+Bundestag,+Berlin");
Intent mapIntent = new Intent(Intent.ACTION_VIEW, location);

// Verify it resolves
PackageManager packageManager = getPackageManager();
List<ResolveInfo> activities = packageManager.queryIntentActivities(mapIntent, 0);
boolean isIntentSafe = activities.size() > 0;

// Start an activity if it's safe
if (isIntentSafe) {

Other example, call a number

Uri number = Uri.parse("tel:123456789");
Intent callIntent = new Intent(Intent.ACTION_DIAL, number);

Uri webpage = Uri.parse("");
Intent webIntent = new Intent(Intent.ACTION_VIEW, webpage);

Get a result from another Activity


Get all hardware sensors (code works within an Activity)

SensorManager sensorManager;
sensorManager=(SensorManager) getSystemService(Context.SENSOR_SERVICE);
List<Sensor> list = sensorManager.getSensorList(Sensor.TYPE_ALL);

Periodic read of the light Sensor

public class SensorActivity extends Activity implements SensorEventListener

    private SensorManager mSensorManager;
    private Sensor mLightSensor;

    protected void onCreate(Bundle savedInstanceState)
        this.mSensorManager=(SensorManager) getSystemService(Context.SENSOR_SERVICE);
        mLightSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);

    protected void onResume()
        //mSensorManager.registerListener(this, mLightSensor, SensorManager.SENSOR_DELAY_NORMAL);
        mSensorManager.registerListener(this, mLightSensor, 5000000);

    protected void onPause()

    public void onSensorChanged(SensorEvent event)
        float lux = event.values[0];
        TextView test = (TextView) findViewById(;

    public void onAccuracyChanged(Sensor sensor, int accuracy)

Saving data



Capturing Photos