Familiarizing with the Environment

A very fun and rewarding part of digging into a new environment is exploring and learning about its bits and pieces. Depending on ambition this can take many years, and since this is a workshop we will only touch upon a few of the fundamentals 😉

To the left we have the Workspace and Projects window with the Package Explorer and Navigator views. The Navigator view is the one that we will use. It roughly corresponds to the file structure in our workspace folder. The workspace is where we keep all our projects e.g. our newly created “helloandroid”. In our project we have a few folders and files. We will focus on two of the folders – “res” and “src” and the AndroidManifest.xml file.

The Manifest file is an XML file and is best viewed in the “xml editor mode”. It describes some of the main properties for the application like version, user-permissions, activities within the app, name of the application, appearance settings etc. For instance we can here see the declaration of our “MainActivity” Activity which is set to:

        <activity android:name=”.MainActivity”
                  android:label=”@string/app_name”>
            <intent-filter>
                <action android:name=”android.intent.action.MAIN” />
                <category android:name=”android.intent.category.LAUNCHER” />
            </intent-filter>
        </activity>

Note the MAIN and the LAUNCHER assignments – they basically tell us that MainActivity will be our entry point into the program.

So let us check out the source for MainActivity. It is located within the “src” folder (through the application package naming structure). MainActivity is a class that extends upon the Activity class – one of the most basic app classes:

    public class MainActivity extends Activity {

The app entry point can now be found in the onCreate function that is called as soon as the app starts:

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }

The first line super.onCreate(savedInstanceState); is not that important right now. The second line though – setContentView(R.layout.main); sets the content view for us. Views are windows of content or content containers that contain elements like text, images, lists, etc. The layout of such Views are most commonly defined in XML files and are located in the “layout” folder within the “res” folder. In the “layout” folder we should look for a main.xml file that we can open in the editor.

In the main.xml we can find the following element:

    <TextView 
        android:layout_width=”fill_parent”
        android:layout_height=”wrap_content”
        android:text=”@string/hello”
    />

This is a simple text element used to write out text on screen. The text it writes out can be found in another xml file (strings.xml) located in the “values” folder within the “res” folder. The name of the string to look for is “hello”. When running the app we should get a view with that text.

Please do check out the Android Developers very own getting started tutorials!