Download Android Studio Beginner's Guide — Java, Android Studio, Absolute Beginner, Complete Java and more Study notes Information Technology in PDF only on Docsity!
Android Studio
Beginner's Guide
3 Complete Java Apps · Phone Connection Guide ·
Troubleshooting
Language: Java | IDE: Android Studio | Level: Absolute Beginner
Simply copy the code and paste it into the correct files, then run!
Section 0 — Setting Up Android Studio 0.1 Installing Android Studio
Android Studio is the official free IDE (Integrated Development Environment) for building Android apps.
Follow these steps:
1. Go to developer.android.com/studio in your browser
2. Click the Download Android Studio button
3. Run the installer (.exe on Windows, .dmg on Mac, or .tar.gz on Linux)
4. In the setup wizard, make sure the following checkboxes are ticked:
- Android Studio
- Android SDK
- Android SDK Platform
- Android Virtual Device (AVD) — this is the emulator
5. Click Next and let the installer finish (can take 10–30 minutes depending on internet speed)
6. Launch Android Studio when installation completes
SYSTEM REQUIREMENTS
Windows: Windows 8/10/11 (64-bit), 8 GB RAM minimum (16 GB recommended), 8 GB free
disk space
Mac: macOS 10.14 (Mojave) or higher, 8 GB RAM, Apple Silicon or Intel processor
Linux: 64-bit GNU/Linux, 8 GB RAM, GNOME or KDE desktop
0.2 Creating Your First Project
Every app you build needs its own project. Here is exactly how to create one:
7. Open Android Studio → Click New Project on the welcome screen
8. On the 'New Project' screen, select Empty Views Activity then click Next
9. Fill in the project details:
- Name: Type your app name (e.g. HelloWorldApp). No spaces allowed.
- Package name: This auto-fills to something like com.example.helloworldapp — leave it as-is
- Save location: Leave as default or choose a folder
- Language: Select Java (NOT Kotlin)
- Minimum SDK: Select API 24 (Android 7.0 Nougat) from the dropdown
10. Click Finish
11. Wait for Gradle to sync — watch the progress bar at the bottom of Android Studio. This can take
2–5 minutes the very first time.
IMPORTANT — Wait for Gradle Sync
Gradle is the build system that downloads your app's dependencies. ALWAYS wait for it to
finish (the progress bar disappears and you see 'BUILD SUCCESSFUL' in the Build tab)
before editing files or running the app. If you edit while Gradle is syncing you may get
confusing errors.
Section 1 — Connecting Your Android Phone
Running your app on a real Android phone gives a much more realistic experience than the emulator.
Your phone will also run the app faster. This section covers everything you need to do.
1.1 Why Use a Real Phone?
- Real performance — much faster than the software emulator
- Accurate touch response, sensors, camera, and GPS
- You can show friends and family your app instantly
- The emulator requires a powerful PC; a real phone does not 1.2 Step 1 — Enable Developer Options on Your Phone
Developer Options is a hidden menu on Android that unlocks advanced features including USB
Debugging. You must enable it before connecting your phone to Android Studio.
HOW TO ENABLE DEVELOPER OPTIONS
Step 1: Open the Settings app on your Android phone
Step 2: Scroll down and tap About Phone
Step 3: Find the entry called Build Number
- On Samsung: Settings > About Phone > Software Information > Build Number
- On Pixel/stock Android: Settings > About Phone > Build Number
- On Xiaomi / Redmi: Settings > About Phone > All Specs > MIUI Version
- On OnePlus: Settings > About Device > Build Number
- On Huawei: Settings > About Phone > Build Number
Step 4: TAP Build Number 7 times in a row quickly
Step 5: You will see the message 'You are now a developer!'
Step 6: Go back to main Settings — you will now see a new option called Developer Options
1.3 Step 2 — Enable USB Debugging
USB Debugging allows Android Studio to communicate with your phone over the USB cable. Without
this, your computer cannot install or run apps on the phone.
12. Open Settings on your phone
13. Scroll to and tap Developer Options (at the bottom of Settings, or under System on some
phones)
14. Make sure the Developer Options toggle at the very top is turned ON (it should be blue/green)
15. Scroll down and find USB Debugging
16. Turn the USB Debugging toggle ON
17. A warning dialog will appear — tap OK to confirm
SECURITY NOTE
USB Debugging is safe to use while you are developing. However, you should turn it OFF
when you are done developing and do not need it anymore. With USB Debugging on,
anyone who connects a USB cable to your phone could potentially access your data if they
know what they are doing. Go back to Developer Options and toggle it off when not in use.
1.4 Step 3 — Connect via USB Cable
This is the easiest and most reliable way to connect your phone.
18. Use a good quality USB cable (preferably the one that came with your phone). Some cheap
USB cables only charge and cannot transfer data — these will NOT work.
19. Plug one end into your Android phone, the other into your computer
20. On your PHONE, a dialog will pop up asking: 'Allow USB Debugging?'
21. Tap Allow (you can also tick 'Always allow from this computer' so the dialog doesn't appear
every time)
22. On your COMPUTER, open Android Studio
23. Look at the toolbar at the top — the device dropdown (where it says 'No Devices' or similar)
should now show your phone's name (e.g. 'Samsung Galaxy A54')
IF YOUR PHONE IS NOT SHOWING UP
Try a different USB cable — data-only cables are a very common issue
On your phone: pull down the notification bar and tap the USB notification
- Change the USB mode from 'Charging only' to 'File Transfer' (also called MTP)
- This is required for the computer to recognise the phone properly
Install the phone's USB driver on your computer:
- Windows: Go to your phone manufacturer's website and download the USB driver
- Mac and Linux: Drivers are usually installed automatically
Restart Android Studio and replug the USB cable
Try a different USB port on your computer
1.5 Step 4 — Install the Correct USB Driver (Windows Only)
On Windows, you may need to install a specific USB driver for your phone brand before it appears in
Android Studio. Here is where to find each manufacturer's driver:
Keyword / Concept What It Means / Does
Samsung samsung.com/us/support — search for 'Samsung USB Driver for
Mobile Phones'
Google Pixel No driver needed. Android ADB driver is included with Android Studio.
Xiaomi / Redmi en.miui.com/thread-281938-1-1.html — download 'Xiaomi USB Driver'
OnePlus oneplus.com/global/support/softwareandfirmware — search USB
driver
38. The app will launch automatically on your phone's screen
39. Any changes you make in Android Studio and re-run will update the app on your phone instantly
IMPORTANT — Stay Unlocked
Your phone screen must be unlocked and awake for Android Studio to install the app on it. If
the screen goes to sleep or you lock the phone during installation, the process may fail.
1.8 Using the Emulator (If You Don't Have a Phone)
The Android Virtual Device (AVD) emulator simulates a phone on your computer. It is slower than a real
phone but works fine for learning.
40. In Android Studio: Tools menu > Device Manager
41. Click Create Device (plus icon)
42. Choose a phone from the list (e.g. Pixel 6) and click Next
43. Download a system image — choose the latest API Level with the 'Download' link next to it and
click Next
44. Leave all settings as default and click Finish
45. Your new virtual device appears in the Device Manager list
46. Click the Play (triangle) button next to it to launch the emulator
47. Wait for it to boot up (can take 2–5 minutes the first time)
48. Once booted, it stays running — you can run apps on it just like a real phone
EMULATOR PERFORMANCE TIP
If the emulator is very slow, make sure Hardware Acceleration is enabled:
Windows: Android Studio > Tools > SDK Manager > SDK Tools > Intel x86 Emulator
Accelerator (HAXM) — install it
Mac (Apple Silicon): The emulator uses Apple's Hypervisor automatically — no extra setup
needed
Also, in Device Manager > select your AVD > Edit (pencil icon) > Show Advanced Settings >
increase RAM to 2048 MB
Section 2 — App 1: Hello World App
This is the simplest possible Android app. It shows a greeting message on screen and has a button the
user can tap to change the message. Every tap increases a counter.
What you will learn: XML layouts, TextView, Button, onClick events, connecting XML to Java with
findViewById().
APP OVERVIEW
App name to use: HelloWorldApp
Number of files to edit: 2 (activity_main.xml and MainActivity.java)
Difficulty: Beginner
Time to complete: 10 minutes
File 1 — activity_main.xml (The Screen Layout)
Path: app > res > layout > activity_main.xml
Open this file in Android Studio, click the 'Code' button at the top right of the editor to switch to text
view, then SELECT ALL (Ctrl+A or Cmd+A) and DELETE everything. Paste the code below.
📄 activity_main.xml
// Connect our Java variables to the XML views using their IDs tvGreeting = findViewById(R.id.tvGreeting); btnClickMe = findViewById(R.id.btnClickMe); // Set up what happens when the button is tapped btnClickMe.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // Each click increases the counter clickCount++; // Update the greeting text tvGreeting.setText("You clicked " + clickCount + " time(s)!"); // After 5 clicks, give a special message if (clickCount >= 5) { tvGreeting.setText("You are a clicking champion!"); } } }); } } Code Explanation — App 1
Keyword / Concept What It Means / Does
LinearLayout The root container. Stacks its children vertically (like a column).
gravity='center' centres everything on screen.
android:id Gives a view a unique name so Java can find it with findViewById().
The @+id/ prefix means 'create a new ID'.
wrap_content Makes the view just big enough to fit its content (text, image, etc.)
match_parent Makes the view fill all available space from its parent container
setContentView() Connects the Java Activity to the XML layout file. Without this line, the
screen would be blank.
findViewById() Searches the layout for a view with the given ID and returns it, so you
can control it from Java.
setOnClickListener() Registers a listener that watches for tap events. The onClick() method
inside runs every time the user taps the button.
clickCount++ Increases the clickCount variable by 1 each time the button is tapped
(++ means 'add 1').
setText() Changes the text displayed by a TextView at runtime (while the app is
running).
Section 3 — App 2: Simple Calculator
A working four-function calculator. The user types two numbers and taps one of four buttons (+, -, x, /)
to see the result. Division by zero is handled safely.
What you will learn: EditText (user text input), reading input, Double.parseDouble(), arithmetic, helper
methods, Toast messages.
APP OVERVIEW
App name to use: CalculatorApp
Number of files to edit: 2 (activity_main.xml and MainActivity.java)
Difficulty: Beginner–Intermediate
Time to complete: 15 minutes
File 1 — activity_main.xml
Path: app > res > layout > activity_main.xml — Select All, Delete, paste below:
📄 activity_main.xml
android:id="@+id/btnDivide" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="/" android:textSize="20sp" android:backgroundTint="#FB8C00" android:layout_margin="4dp" />
File 2 — MainActivity.java
Path: app > java > com.example.calculatorapp > MainActivity.java
📄 MainActivity.java package com.example.calculatorapp; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; import androidx.appcompat.app.AppCompatActivity; public class MainActivity extends AppCompatActivity { private EditText etNumber1, etNumber2; private Button btnAdd, btnSubtract, btnMultiply, btnDivide; private TextView tvResult; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);
// Connect Java variables to XML views etNumber1 = findViewById(R.id.etNumber1); etNumber2 = findViewById(R.id.etNumber2); btnAdd = findViewById(R.id.btnAdd); btnSubtract = findViewById(R.id.btnSubtract); btnMultiply = findViewById(R.id.btnMultiply); btnDivide = findViewById(R.id.btnDivide); tvResult = findViewById(R.id.tvResult); // --- ADDITION BUTTON --- btnAdd.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (inputsAreValid()) { double n1 = Double.parseDouble(etNumber1.getText().toString()); double n2 = Double.parseDouble(etNumber2.getText().toString()); double answer = n1 + n2; tvResult.setText("Result: " + answer); } } }); // --- SUBTRACTION BUTTON --- btnSubtract.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (inputsAreValid()) { double n1 = Double.parseDouble(etNumber1.getText().toString()); double n2 = Double.parseDouble(etNumber2.getText().toString()); double answer = n1 - n2; tvResult.setText("Result: " + answer); } } }); // --- MULTIPLICATION BUTTON --- btnMultiply.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (inputsAreValid()) { double n1 = Double.parseDouble(etNumber1.getText().toString()); double n2 = Double.parseDouble(etNumber2.getText().toString()); double answer = n1 * n2; tvResult.setText("Result: " + answer); } } }); // --- DIVISION BUTTON ---
layout_weight='1' Divides the available space equally among all buttons in the row. Four
buttons each get weight=1, so each takes 25% of the width.
Toast.makeText() Shows a short pop-up notification at the bottom of the screen.
LENGTH_SHORT shows it for about 2 seconds.
private boolean
method()
A method that returns either true or false. We use it to check
conditions before doing something risky (like parsing a number).
Section 4 — App 3: To-Do List App
A functional to-do list manager. The user can type tasks, add them to a scrollable list, tap any task to
delete it (with a confirmation dialog), and clear all tasks at once.
What you will learn: ArrayList, ArrayAdapter, ListView, item click events, AlertDialog confirmation
boxes.
APP OVERVIEW
App name to use: TodoListApp
Number of files to edit: 2 (activity_main.xml and MainActivity.java)
Difficulty: Intermediate
Time to complete: 20 minutes
File 1 — activity_main.xml
Path: app > res > layout > activity_main.xml — Select All, Delete, paste below:
📄 activity_main.xml
android:backgroundTint="#C62828" android:textColor="#FFFFFF" android:layout_margin="12dp" />
File 2 — MainActivity.java 📄 MainActivity.java package com.example.todolistapp; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.EditText; import android.widget.ListView; import android.widget.Toast; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; import java.util.ArrayList; public class MainActivity extends AppCompatActivity { private EditText etTask; private Button btnAddTask, btnClearAll; private ListView lvTasks; // The list that holds all task strings in memory private ArrayList taskList; // The adapter connects taskList to the ListView on screen private ArrayAdapter adapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); etTask = findViewById(R.id.etTask); btnAddTask = findViewById(R.id.btnAddTask); btnClearAll = findViewById(R.id.btnClearAll); lvTasks = findViewById(R.id.lvTasks); // Create an empty list to store tasks taskList = new ArrayList<>(); // Create an ArrayAdapter:
// - 'this' = context (the current Activity) // - android.R.layout.simple_list_item_1 = a built-in row layout // - taskList = the data to display adapter = new ArrayAdapter<>( this, android.R.layout.simple_list_item_1, taskList ); // Attach the adapter to the ListView lvTasks.setAdapter(adapter); // ── ADD TASK BUTTON ────────────────────────────────────── btnAddTask.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String taskText = etTask.getText().toString().trim(); if (taskText.isEmpty()) { Toast.makeText(MainActivity.this, "Please enter a task first!", Toast.LENGTH_SHORT).show(); return; // Stop here } taskList.add(taskText); // Add to list adapter.notifyDataSetChanged(); // Refresh screen etTask.setText(""); // Clear the input Toast.makeText(MainActivity.this, "Task added!", Toast.LENGTH_SHORT).show(); } }); // ── TAP A TASK TO DELETE IT ────────────────────────────── lvTasks.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView parent, View view, int position, long id) { final String selectedTask = taskList.get(position); // Show a confirmation dialog before deleting new AlertDialog.Builder(MainActivity.this) .setTitle("Delete Task?") .setMessage("Remove: " + selectedTask) .setPositiveButton("Delete", (dialog, which) -> { taskList.remove(position); adapter.notifyDataSetChanged(); Toast.makeText(MainActivity.this, "Task deleted", Toast.LENGTH_SHORT).show(); }) .setNegativeButton("Cancel", null) .show();