Courses / Mobile Application Development (CDE-315) – BS CS 5th Semester

Week 1 Lab 1 – Install Android Studio and Create a "Hello World" Application

Week 1 – Introduction to Mobile Applications and Platforms · 120 min read · 16 MCQs to check yourself

How to create your first Android app in Android Studio

Objective

Install Android Studio, create your first Java Android app, run it on an emulator or phone, and understand where each file of a project lives. CLOs: CLO-2 (develop an app with a current environment), CLO-4 (use modern tools – Android Studio, SDK, emulator).

The CampusMate project (used in every lab)

In this course you build one app step by step – CampusMate, a small app for students of your campus. Each lab adds one feature:

Lab Feature added to CampusMate
1 Create the project – welcome screen
3 Student card from resources (image + name)
4 Profile screen (second activity, passing data)
5 Bottom navigation: Home, Courses, Profile
6 Visit website and call office buttons
7 Registration form
8 Menu: About, Help, Logout
10 Login that remembers the username
11 Contact teacher by SMS / email
12 Campus notices from an online API
13 Quiz countdown timer
14 Campus on Google Maps
15 My current location
16 Build the APK and install it
17 Mini project: Campus Feedback (form + timer + location + email)

Lab 2 is a web lab: the CampusMate mobile web page.

Keep one project folder for the whole semester (e.g. D:\AndroidProjects\CampusMate) and back it up (USB/Google Drive/GitHub) after every lab. If you miss a lab, create the files of that lab in your project before the next one.

Workflow

Step What you do Where
1 Check your PC and install Android Studio developer.android.com/studio
2 Create the CampusMate project (Java) New Project wizard
3 Edit the welcome screen layout res/layout/activity_main.xml
4 Write the Java code for the button MainActivity.java
5 Create an emulator and run the app Device Manager → Run ▶
6 Run on your own phone (optional) USB debugging
7 Explore the project structure Project view

Step 1 – Check the computer and install Android Studio

Item Minimum (recommended)
OS 64-bit Windows 10/11, macOS or Linux
RAM 8 GB (16 GB for a smooth emulator)
Disk 8 GB free (SSD recommended)
CPU Virtualisation (Intel VT-x / AMD-V) enabled in BIOS
Internet Needed for the first setup (about 2–3 GB download)
  1. Download Android Studio from developer.android.com/studio.
  2. Windows: run the installer → keep Android Virtual Device ticked → Next → Finish.
  3. First launch → Setup Wizard → Standard → accept licences → it downloads the Android SDK, Platform-Tools (adb) and the Emulator.

Low-RAM PC (4 GB)? Skip the emulator and use a real phone (Step 6).

Step 2 – Create the CampusMate project

File → New → New Project → Phone and Tablet → Empty Views Activity → Next, then fill in:

Field Value
Name CampusMate
Package name com.example.campusmate
Save location D:\AndroidProjects\CampusMate (no spaces in the path)
Language Java
Minimum SDK API 24 (Android 7.0)
Build configuration language Kotlin DSL (default – this is only the build file, our code is Java)

Click Finish and wait for Gradle sync to finish (bottom status bar).

Choose Empty Views Activity, not Empty Activity (that one uses Jetpack Compose). All our labs use XML layouts + Java.

Step 3 – Design the welcome screen

Open app/src/main/res/layout/activity_main.xml → Code view → replace everything with:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:gravity="center"
    android:orientation="vertical"
    android:padding="24dp">

    <TextView
        android:id="@+id/tvWelcome"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Welcome to CampusMate"
        android:textSize="26sp"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/tvSubtitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        android:text="Your campus in your pocket" />

    <Button
        android:id="@+id/btnHello"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="24dp"
        android:text="Say Hello" />
</LinearLayout>

Step 4 – Write the Java code

Open app/src/main/java/com/example/campusmate/MainActivity.java and replace the class with:

package com.example.campusmate;

import android.os.Bundle;
import android.util.Log;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    private TextView tvWelcome;      // 1. declare the views we will use
    private Button btnHello;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);       // 2. show the XML layout

        tvWelcome = findViewById(R.id.tvWelcome);      // 3. connect Java to XML
        btnHello = findViewById(R.id.btnHello);

        Log.d("CampusMate", "MainActivity started");   // message in Logcat

        btnHello.setOnClickListener(v -> {             // 4. react to a click
            tvWelcome.setText("Hello, BSCS student!");
            Toast.makeText(this, "Welcome to MAD lab", Toast.LENGTH_SHORT).show();
        });
    }
}

If the template added EdgeToEdge.enable(this) and a ViewCompat.setOnApplyWindowInsetsListener(...) block, you may delete them – our layout already uses fitsSystemWindows.

The 4-step pattern you will use in every lab: declare views → setContentView → findViewById → setOnClickListener.

Step 5 – Create an emulator and run

  1. Tools → Device Manager → + (Create Virtual Device) → choose Pixel 8 → Next.
  2. Download a system image (latest stable, x86_64) → Next → Finish.
  3. Select the emulator in the toolbar and click Run ▶ (Shift+F10).
  4. The app opens; tap Say Hello – the text changes and a Toast appears.

Step 6 – Run on your phone (optional)

  1. Phone: Settings → About phone → tap Build number 7 times → Developer options are enabled.
  2. Developer options → USB debugging → On.
  3. Connect the USB cable → allow the "USB debugging" prompt → select the phone in Android Studio → Run ▶.

Step 7 – Understand the project structure (Android view)

Folder / file What it contains
manifests/AndroidManifest.xml App name, icon, activities, permissions
java/com.example.campusmate/ Your Java classes (MainActivity.java)
res/layout/ XML screen designs
res/values/ strings.xml, colors.xml, themes.xml
res/drawable/ Images and shapes
res/mipmap/ Launcher icons
Gradle Scripts/build.gradle.kts (Module :app) applicationId, minSdk, targetSdk, dependencies

Open Logcat (bottom bar), type CampusMate in the filter and see your log message.

Run and test

Test Expected result
Launch the app "Welcome to CampusMate" in the centre
Tap Say Hello Text changes to "Hello, BSCS student!" and a Toast shows
Logcat filter CampusMate "MainActivity started"

Common errors and fixes

Problem Fix
Gradle sync failed Check internet → File → Sync Project with Gradle Files
"Cannot resolve symbol R" Fix any red XML error, then Build → Rebuild Project
Emulator very slow / won't start Enable virtualisation in BIOS, close Chrome, or use a phone
App crashes at the button The id in findViewById(R.id.btnHello) must match @+id/btnHello in XML
Phone not shown Accept the USB debugging prompt; try another cable/USB port

Short and long questions

1. (Viva) What is the difference between the Android SDK and Android Studio?

Model answer

The Android SDK is the set of libraries, APIs, platform tools (adb), build tools, emulator and system images needed to build Android apps. Android Studio is the IDE (editor, designer, debugger, Gradle integration) that uses the SDK to create, build and run apps.

2. (Viva) What does setContentView() do?

Model answer

It inflates the given XML layout resource (for example R.layout.activity_main) and sets it as the user interface of the activity.

3. (Viva) How do you run an app on a real Android phone?

Model answer

Enable Developer options by tapping Build number 7 times, turn on USB debugging, connect the phone with a data cable and accept the debugging prompt (or pair with Wireless debugging), then select the phone in Android Studio and press Run.

4. (Viva) Why should text be placed in strings.xml instead of hard-coding it?

Model answer

Keeping text in strings.xml separates content from code, allows the same string to be reused, and makes translation (localisation) easy by adding values-ur/strings.xml etc. without changing code.

5. (Viva) Name the main folders of an Android project and what each contains.

Model answer

manifests (AndroidManifest.xml – components, permissions), java (our Java source code, e.g. MainActivity.java), res/layout (XML screens), res/values (strings, colours, themes), res/drawable (images), res/mipmap (launcher icons), and the Gradle scripts (build configuration and dependencies).

This lesson ends with a quiz of 16 MCQs. Open the lesson on PrepOasis to take it and save your progress.

Previous: Week 1 Theory – Introduction and Importance of Mobile Applications; Mobile Application Development Platforms · Next: Week 2 Theory – HTML5 for Mobiles – Responsive Pages, Mobile Forms, Device APIs and PWAs

All lessons in Mobile Application Development (CDE-315) – BS CS 5th Semester