Intro to Android

Lab: Add Application

Add to the manifest

Let's add the following attribute to our <application/> tag of our AndroidManifest.xml.

<application
    android:label="@string/app_name"
    android:icon="@drawable/calc_icon"
    android:name=".CalculatorApplication">

Create class

Create a file called CalculatorApplication.java in the package structure. You can use the IDE to create it for you or do it manually.

It's best practice to set it up as a singleton.

public class CalculatorApplication extends Application
{
    private static CalculatorApplication instance = new CalculatorApplication();

    public static CalculatorApplication getInstance()
    {
        return instance;
    }
}

Write Test

Create a file called CalculatorApplicationTest.java in your test package structure. You can use the IDE to create it for you or do it manually.

Let's add the basic non-null test:

public class CalculatorApplicationTest
{
    @Test
    public void shouldNotBeNull() throws Exception
    {
        assertNotNull( CalculatorApplication.getInstance() );
    }
}

That's it! Now we can add more items to this class as we need them.

Let's commit our changes.