Android App Programming 2021-2022

Lab 1: Android Studio Setup, Activities

The goal of this lab is to set up your Android working environment and to create your first simple interactive app.

1. Android Studio Setup

  1. Boot up Android Studio. It may require you to download an sdk (agree and look at notes on proxy under "Some common problems ...").

    If you are propted to install an SDK to donwload, go to Tools > SDK manager and get the latest.

  2. Create a new project (Empty Activity). Choose any name, Java as language and minumum API level 21 (Android 5). This may take a bit as Android Studio may fetch a few things.

  3. Click on the "Run app" button and create a new virtual device. Choose an Android emulator. If no device emulator is present, create one. Go to Tools > AVD manager and create a new one. You can choose a Pixel 3 with Android 5.0 (or Nexus 5X with Android 6.0). Then launch your app on the emulated device.

  4. Launch your app on the emulator. Once you get it running, change the text label to something else, rotate the label, and run it again.

  5. After successfully launching your app on the emulator, connect your Android device via USB to the PC and run your app on the physical device. All devices from the Uni are setup properly. If you are using your own, make sure the physical mobile device is open for development (under System > Parameters there exists a “{} Options pour les developers", if not see Setting up your environment ...)

    If the physical device does not appear under devices / run options, then go to Tools > Troubleshoot device and follow steps until the devicedevice is seen. If your mobile device prompts you to accept connections from your desktop, say yes.

    When the class is finished, if you are using a device from the uni, turn it off (éteindre) otherwise they will run out of battery! Give them back to Anastasia on your way out.


  6. Some common problems of the lab environment:


    Setting up your environment at home, or using your own Android:


    2. Simple Activity

    Create a new project that is an "Empty Activity". Analyze the different files the project contains. In particular, study the files MainActivity.java, and activity_main.xml.

    Do the following changes to the project:

    1. Rotate the text of the TextView "Hello World! by 45o.
    2. Add a button (hint: look at the activity_main.xml layout). Check for warnings / errors on the name of the Button (follow recommendations) and check the result in the res/values/string.xml. Also check the error on the layout constraints and try to use the arrows to fix the layout of the button.

      Why do you think strings are stored in a seperate file? Why do you think layout constraints are important?

    3. In the Common Attributes of your Button add the name of a method under OnClick (the new method will eventually become your Listener). Look at the warning in your xml code and follow the recommendation to create the method in MainActivity.java. In your new method make your button do something: try to make your button change the TextField text. You can use the method findViewById(R.id.foo) to access a widget with name foo defined in the activity_main.xml.


    3. Simple Game

    1. Create an app that asks the user a sequence of multiple choice questions (2-3 questions, with 3 answers each) and then displays the number of correct answers given by the user.

      There are multiple ways to do this, try to use a different layout and new widgets (e.g., radio buttons). You can use a mix of the UI editor and xml source to edit activity_main.xml.

      Methods that may be of interest: RadioButton.getChecked(), RadioGroup.getCheckedRadioButtonId()

    2. Once you are done, refine your app by highlighting the correct and wrong choices.

    back to the course web site