The anatomy of an Android project

In the project overview on the left-hand side, you’ll see quite a few folders and files. Here’s an overview:

  • res/layout/activity_main.xml
    • Here’s the layout for our main activity! We’ll get back to this in a moment.
  • res/mipmap/ic_launcher
    • This is our app’s icon, which will be displayed on the home screen (back in Android 1.x, this was called the “launcher”).
    • It comes in many different sizes. Which size is used depends on the phone. If you create a high-resolution icon, Studio can generate scaled versions to make it automatically look good on any phone.
  • res/values/styles.xml
    • Controls how the app will look (colors, font sizes etc)
    • Right now, we inherit our AppTheme from Theme.AppCompat.Light.DarkActionBar. Because dark apps look better, remove .Light.DarkActionBar to switch to the dark version.
    • If you want, try to get rid of the awful default colors as well!
  • java/no.hackerspace_ntnu.deadline/MainActivity
    • This is where we write the Java/Kotlin code to “communicate” with the user. Long story short: we put views on the screen, and react when the user touches them. Right now, all we do is to tell Android where to find the activity_main.xml layout file.
    • Notice: this class extends AppCompatActivity, which in turn extends Activity. These two classes contain lots of code to make our lives easier. The Activity class ships with every Android device out there, and is technically not part of our app. Google makes changes to this class in almost every new Android version, and after a few years it started getting really hard to keep track of what parts of Activity you could use and how it would behave on different devices.
      To make this easier, Google made AppCompat, a library (aka. pile of code) that makes almost everything work exactly the same way no matter what device our app is running on. AppCompatActivity is shipped with our app, and is the same no matter what device the app is running on.
  • app/manifests/AndroidManifest.xml
    • This file tells Android what our app is called, what it can do, which permissions it needs and so on.
    • Notice how it uses our icon, app style and other resources from the `res` folder: @resource_type/resource_name
    • The <activity android:name=”.MainActivity”> tag is very interesting. Here, we are telling Android how users can enter our app. In our case, we see that the app can be opened from the home screen (“launcher”).
  • Gradle scripts
    • Gradle is the build system that makes everything work together.

Now that you know everything about how Android works (heh), let’s start coding our app!

Next: Making a layout