MAD U1
MAD U1
The Linux kernel serves as the core of the Android OS, handling:
Device Drivers: Controls hardware components (WiFi, Bluetooth, audio, camera, display, etc.).
Process Management: Schedules tasks and manages CPU resources.
Memory Management: Allocates RAM efficiently among apps and system processes.
Security Features: Uses SELinux (Security-Enhanced Linux) to enforce security policies.
Power Management: Optimizes battery usage through power-efficient modes (e.g., Doze
Mode).
Binder IPC (Inter-Process Communication): Essential for communication between processes
and system services.
🔹 Why It Matters?
The Linux kernel provides stability, security, and hardware abstraction for all Android
devices.
🔹 2. Hardware Abstraction Layer (HAL)
The HAL acts as a bridge between the Linux Kernel and the higher-level software layers.
It provides APIs for accessing hardware components without exposing kernel details.
HAL Components:
🔹 Why It Matters?
HAL allows device manufacturers to implement their hardware features while keeping the
Android system consistent across devices.
This layer consists of native libraries and the Android Runtime (ART).
The Android Runtime (ART) replaces the older Dalvik VM for running Android applications.
ART Features:
Ahead-of-Time (AOT) Compilation: Apps are compiled before execution, reducing load times.
Just-in-Time (JIT) Compilation: Optimizes performance by compiling only needed code during
runtime.
Garbage Collection (GC): Automatically manages memory, preventing memory leaks.
Dex (Dalvik Executable) Files: Converts Java bytecode to optimized DEX format for execution.
🔹 Why It Matters?
ART improves performance, battery life, and app efficiency compared to Dalvik VM.
🔹 4. Application Framework
The Application Framework provides APIs that developers use to build Android apps.
Key Components:
Activity Manager – Manages the lifecycle of applications and activities.
Window Manager – Controls screen UI components and transitions.
Package Manager – Handles app installations, updates, and permissions.
Content Providers – Enables apps to share and access structured data (e.g., Contacts, Files).
Location Manager – Provides location-based services using GPS/WiFi.
Telephony Manager – Manages SIM card, network calls, and SMS.
Notification Manager – Controls push notifications and system alerts.
Resource Manager – Manages UI elements like layouts, strings, images, and themes.
🔹 Why It Matters?
The Application Framework abstracts complex system interactions, enabling developers to
build powerful and efficient applications.
This is the topmost layer, where users interact with the system through system apps and third-
party applications.
Includes:
🔹 Why It Matters?
This layer provides the user interface and experience, ensuring app security and
performance.
🔹 1. Security Model
🔹 2. Power Management
✔Doze Mode & App Standby – Saves battery by limiting background activities.
✔Adaptive Battery – AI-based optimizations to extend battery life.
✔Seamless A/B Partition Updates – Updates install in the background without affecting usage.
🔹 Summary
Layer Description
Hardware Abstraction Layer (HAL) Interface between hardware & Android framework
Native Libraries & ART Graphics, database, web, media libraries + ART for app execution
Application Framework APIs for app development (Activity Manager, Location Manager, etc.)
🔹 Why It Matters?
This design ensures scalability, easy maintenance, and faster updates.
🔹 Why It Matters?
Android prioritizes user data protection, privacy, and system integrity.
🔹 Why It Matters?
ART delivers better battery life, smoother UI performance, and reduced app load times.
🔹 Why It Matters?
These optimizations significantly extend battery life.
🔹 Why It Matters?
Android provides a consistent and flexible UI across different devices.
🔹 6. Multi-Tasking & Multi-Window Support
🔹 Why It Matters?
Improves productivity and user experience, especially for large-screen devices.
🔹 Why It Matters?
Provides seamless internet and device communication.
🔹 Why It Matters?
Enhances automation, personalization, and intelligent system optimizations.
🔹 Why It Matters?
Ensures faster, seamless, and more frequent software updates.
The framework consists of multiple layers, each serving a specific purpose in app development:
Let me generate a diagram to visually represent the framework for better understanding. 🎨
🎨 What it is?
The topmost layer where system apps (Phone, Messages, Camera) and user-installed apps run.
Provides the User Interface (UI) for interacting with the device.
🎨 Key Components:
✔System Apps – Pre-installed apps like Phone, Contacts, and Settings.
✔Third-Party Apps – Apps installed by users from the Play Store.
✔User Interface (UI) – Designed using XML, Jetpack Compose, and Material Design.
🎨 Why it Matters?
🎨 What it is?
🎨 Key Components:
✔Activity Manager – Manages app lifecycle and activity stack.
✔Window Manager – Handles screen layout, transitions, and rendering.
✔Notification Manager – Manages push notifications and alerts.
✔Content Providers – Allows apps to share data securely (e.g., Contacts, Calendar).
✔Resource Manager – Manages UI elements (strings, layouts, images).
🎨 Why it Matters?
This layer ensures app functionality and seamless integration with system resources.
🎨 What it is?
🎨 Key Components:
✔ART (Android Runtime) – Uses JIT (Just-in-Time) & AOT (Ahead-of-Time)
Compilation for faster app execution.
✔OpenGL ES – Handles 2D & 3D graphics rendering for games and UI.
✔SQLite – Manages local app databases.
✔WebKit – Provides web browsing functionalities inside apps.
✔Media Framework – Supports audio, video, and image processing.
🎨 Why it Matters?
Optimizes app performance, reduces memory usage, and enhances multimedia experiences.
🎨 What it is?
🎨 Key Components:
✔Camera HAL – Allows apps to access the camera module.
✔Audio HAL – Manages speaker, microphone, and media playback.
✔Sensors HAL – Enables motion detection, gyroscope, and accelerometer.
✔Bluetooth & WiFi HAL – Controls wireless communication features.
🎨 Why it Matters?
Allows Android to run on different hardware configurations without modifying the OS core.
🎨 What it is?
The foundation of Android OS, handling hardware interactions, security, and memory
management.
🎨 Key Components:
✔Device Drivers – Controls hardware (WiFi, Bluetooth, Display, Camera, etc.).
✔Memory Management – Allocates RAM efficiently.
✔Process Management – Manages CPU tasks and system performance.
✔Security (SELinux) – Ensures data privacy and app sandboxing.
✔Binder IPC (Inter-Process Communication) – Enables communication between system
processes.
🎨 What it is?
Android Studio is the official Integrated Development Environment (IDE) for Android
development.
Provides tools for writing, debugging, testing, and profiling applications.
🎨 Key Features:
✔Intelligent code editor with Kotlin & Java support.
✔UI Design tools for drag-and-drop layout creation.
✔Gradle-based build system for automation.
🎨 Real-World Example:
✅Instagram – Developed using Android Studio, Instagram uses its UI tools to design its
dynamic interface and profiling tools to optimize performance.
🎨 What it is?
Prebuilt libraries that allow access to Android functionalities like camera, GPS, notifications, and
media playback.
Includes Android Jetpack for modern app development.
🎨 Key Features:
✔Camera API – Access and control the device camera.
✔Location API – Fetch GPS coordinates and provide navigation.
✔Firebase API – Push notifications, authentication, and analytics.
🎨 Real-World Example:
✅Google Maps – Uses Location API to provide real-time navigation and GPS tracking.
✅Uber – Uses Firebase API for real-time trip notifications.
🎨 What it is?
The Android Virtual Device (AVD) emulator allows developers to test apps on different device
configurations.
Ensures apps work on different screen sizes, resolutions, and Android versions.
🎨 Key Features:
✔Test on multiple devices without physical hardware.
✔Supports foldable screens & wearables (Wear OS, TV, Auto).
✔Allows real-time debugging and performance monitoring.
🎨 Real-World Example:
✅TikTok – Uses emulators to test app performance on low-end and high-end devices before
release.
🎨 What it is?
Gradle Build System compiles, optimizes, and packages apps for deployment.
Supports APK (Android Package) & AAB (Android App Bundle) formats.
🎨 Key Features:
✔Dependency Management – Auto-downloads required libraries.
✔ProGuard & R8 – Shrinks code and optimizes app performance.
✔Multi-platform compatibility – Builds apps for different Android versions.
🎨 Real-World Example:
✅Spotify – Uses Gradle to automate builds, ensuring smooth app updates.
🎨 What it is?
🎨 Key Features:
✔Push and pull files between PC and Android devices.
✔Remotely install & uninstall apps.
✔Access system logs & debug crashes.
🎨 Real-World Example:
✅Samsung Developers – Use ADB to debug One UI features on Samsung Galaxy devices
before release.
🎨 What it is?
Includes tools like Android Profiler to track CPU usage, memory leaks, battery consumption,
and network performance.
🎨 Key Features:
✔CPU Profiler – Monitors how much CPU an app consumes.
✔Memory Profiler – Detects memory leaks and RAM usage.
✔Network Profiler – Monitors internet requests and responses.
🎨 Real-World Example:
✅YouTube – Uses profiling tools to optimize video playback and reduce buffering issues.
🎨 What it is?
The SDK supports development in Java, Kotlin, C++, Dart (Flutter), and JavaScript (React
Native).
🎨 Key Features:
✔Kotlin-first approach for modern app development.
✔C++ NDK support for performance-intensive apps.
✔Flutter & React Native integration for cross-platform apps.
🎨 Real-World Example:
✅WhatsApp – Uses Kotlin for app logic and C++ for encryption algorithms.
You will be delighted, to know that you can start your Android application
development on either of the following operating systems −
Overview
Android Studio is the official IDE for android application development.It works based
on IntelliJ IDEA, You can download the latest version of android studio
from Android Studio 2.2 Download, If you are new to installing Android Studio on
windows,you will find a file, which is named as android-studio-bundle-143.3101438-
windows.exe.So just download and run on windows machine according to android
studio wizard guideline.
If you are installing Android Studio on Mac or Linux, You can download the latest
version from Android Studio Mac Download,or Android Studio Linux Download,
check the instructions provided along with the downloaded file for Mac OS and
Linux. This tutorial will consider that you are going to setup your environment on
Windows machine having Windows 8.1 operating system.
Installation
So let's launch Android Studio.exe,Make sure before launch Android Studio, Our
Machine should required installed Java JDK. To install Java JDK,take a references
of Android environment setup
Once you launched Android Studio, its time to mention JDK7 path or later version in
android studio installer.
Need to specify the ram space for Android emulator by default it would take 512MB
of local machine RAM.
At final stage, it would extract SDK packages into our local machine, it would take a
while time to finish the task and would take 2626MB of Hard disk space.
After done all above steps perfectly, you must get finish button and it gonna be
open android studio project with Welcome to android studio message as shown
below
You can start your application development by calling start a new android studio
project. in a new installation frame should ask Application name, package
information and location of the project.
After entered application name, it going to be called select the form factors your
application runs on, here need to specify Minimum SDK, in our tutorial, I have
declared as API23: Android 6.0(Mashmallow)
The next level of installation should contain selecting the activity to mobile, it
specifies the default layout for Applications
At the final stage it going to be open development tool to write the application code.
Step 3 - Create Android Virtual Device
To test your Android applications, you will need a virtual Android device. So before
we start writing our code, let us create an Android virtual device. Launch Android
AVD Manager Clicking AVD_Manager icon as shown below
After Click on a virtual device icon, it going to be shown by default virtual devices
which are present on your SDK, or else need to create a virtual device by
clicking Create new Virtual device button
If your AVD is created successfully it means your environment is ready for Android
application development. If you like, you can close this window using top-right cross
button. Better you re-start your machine and once you are done with this last step,
you are ready to proceed for your first Android example but before that we will see
few more important concepts related to Android Application Development.
Before Writing a Hello word code, you must know about XML tags.To write hello word
code, you should redirect to App>res>layout>Activity_main.xml
To show hello word, we need to call text view with layout ( about text view and
layout, you must take references at Relative Layout and Text View ).
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
</RelativeLayout>
Creating AVDs
Step 1: Open Android Studio
Ensure you have Android Studio installed. If not, download and install it from the official website.
1. In the Android Virtual Device Manager window, click on Create Virtual Device.
Step 4: Choose Hardware
1. Select a device from the list of available device profiles. If you need a specific device, you can also click on New
Hardware Profile to create a custom one.
2. Once you select a device (like Pixel 4, Nexus 5X, etc.), click Next.
1. You'll be prompted to select a system image (Android version). If you don’t have the system image you want, you
can download it by selecting the version under Recommended, x86 Images, or Other Images.
2. Choose the system image you want (e.g., a specific Android version) and click Next.
1. Set configurations like AVD name, orientation (portrait or landscape), RAM size, and more. You can also adjust
other settings like the device’s performance options.
2. Optionally, you can enable features like Graphics (Software or Hardware) and Camera (for testing apps that use
camera features).
Definition: These are applications developed specifically for the Android operating system using Android SDK and
Java/Kotlin.
Examples: Social media apps, messaging apps, camera apps, etc.
Characteristics: They provide high performance and full access to device features (GPS, camera, sensors, etc.).
2. Web Applications
Definition: These are applications that run on a web browser on Android devices. They are developed using web
technologies like HTML, CSS, and JavaScript.
Examples: Websites that behave like apps, such as mobile banking or online shopping platforms.
Characteristics: Web apps are platform-independent and do not need to be installed on the device. They require
internet connectivity.
3. Hybrid Applications
Definition: Hybrid apps combine elements of both native and web apps. They are written using web technologies
(HTML, CSS, JavaScript) but packaged inside a native Android container using frameworks like Cordova, Ionic, or
React Native.
Examples: Apps like Instagram, Facebook (earlier versions).
Characteristics: They can access device features through plugins and are cross-platform, allowing deployment on
both Android and iOS.
4. Games
Definition: These are apps specifically designed for gaming, typically using graphics-heavy frameworks like Unity
or Unreal Engine.
Examples: Action games, strategy games, puzzle games, etc.
Characteristics: Games often require intensive graphics and high CPU performance, making them resource-
intensive.
5. Enterprise Applications
Definition: These apps are developed for business or organizational purposes. They include apps for managing
tasks, inventory, employees, etc.
Examples: Salesforce, Microsoft Office Suite, enterprise resource planning (ERP) apps.
Characteristics: These apps are secure, scalable, and often have features for data synchronization and analytics.
6. Utility Applications
Definition: These apps are designed to enhance the usability of the Android device, providing tools or utilities.
Examples: File managers, antivirus apps, calculators, flashlight apps.
Characteristics: They are usually lightweight and serve specific, practical purposes.
7. Productivity Applications
Definition: Apps that help users stay organized and productive, such as note-taking, calendar, email, or project
management tools.
Examples: Google Keep, Trello, Evernote, Google Calendar.
Characteristics: These apps focus on improving user efficiency and productivity.
Definition: Apps designed to help users connect, share, and interact with content or other users.
Examples: Facebook, Twitter, Instagram, LinkedIn.
Characteristics: They include features like messaging, photo sharing, video streaming, and social interaction.
9. Entertainment Applications
Definition: Apps focused on providing entertainment through content like movies, music, and videos.
Examples: YouTube, Spotify, Netflix, TikTok.
Characteristics: These apps generally involve media streaming and are often resource-heavy.
Definition: Apps designed to provide educational content and learning resources for users of all ages.
Examples: Duolingo, Khan Academy, Google Classroom.
Characteristics: They help users acquire new knowledge, learn new skills, or prepare for exams.
Definition: Apps that allow users to browse and purchase goods or services online.
Examples: Amazon, eBay, Walmart.
Characteristics: These apps integrate payment gateways, shopping carts, and order management systems.
Definition: Apps designed to deliver news, articles, and other media content to users.
Examples: BBC News, The New York Times, Flipboard.
Characteristics: These apps provide real-time news updates, magazines, and articles tailored to users’ interests.
Definition: Apps that provide financial services, banking, investment, and budgeting tools.
Examples: PayPal, Mint, Robinhood, mobile banking apps.
Characteristics: They require strong security features for protecting sensitive financial data.
MVVM (Model-View-ViewModel) and MVP (Model-View-Presenter) are architecture patterns that separate
concerns and make code more modular and testable.
MVVM works especially well with LiveData and ViewModel classes from the Android Architecture Components.
MVP separates logic and UI, making the app easier to manage.
These architectures help in creating separated, testable, and reusable code.
Memory Management: Use View Recycling in ListViews and RecyclerViews to handle large lists.
Avoid Memory Leaks: Use proper lifecycle management and avoid keeping references to views or context objects
that outlive their lifecycle.
Optimize Image Loading: Use libraries like Glide or Picasso to load images efficiently.
Minimize the main thread load by offloading tasks like network calls or heavy computations to background threads
(using AsyncTask, Threads, or Coroutines).
Jetpack provides a set of libraries that simplify development and help adhere to best practices.
o Room for local database management.
o LiveData and ViewModel for managing UI-related data in a lifecycle-conscious way.
o WorkManager for background tasks.
o Navigation Component for handling in-app navigation.
o DataBinding for reducing boilerplate code related to UI updates.
Navigation Component makes managing fragment transactions, up/back navigation, and deep links easier.
Android runs on a variety of screen sizes, so make your app responsive by using ConstraintLayout and
RelativeLayout.
Use dp and sp for dimension units (density-independent pixels and scale-independent pixels) to ensure the app
adapts to different screen densities and user preferences (font size).
Test layouts in multiple screen orientations (portrait, landscape) and sizes (tablets, phones).
R8 (which replaces ProGuard) helps minify and obfuscate your code to reduce APK size and make reverse-
engineering harder.
It also optimizes bytecode, improving app performance.
Android components (activities, fragments) are lifecycle-dependent. Make sure you handle lifecycle events
properly to avoid memory leaks or app crashes.
Use ViewModel and LiveData to manage UI-related data across configuration changes (such as screen rotations).
Always use onPause() and onResume() wisely to release and reacquire resources (like sensors, camera, etc.).
Network Calls: Minimize the number of network requests, and handle errors (like timeouts, connectivity issues)
gracefully. Use Retrofit or Volley for making network requests.
Battery Optimization: Avoid excessive background processing, use JobScheduler or WorkManager for tasks
that can be deferred or scheduled, and prefer GCM (Google Cloud Messaging) or Firebase Cloud Messaging over
constant polling for notifications.
Use Doze Mode and App Standby to optimize the app’s power consumption.
Unit Testing: Use JUnit for unit testing and ensure that your business logic is correctly implemented.
UI Testing: Use Espresso for testing UI components, such as clicking buttons, navigating between screens, and
validating that the app responds correctly to user input.
Automated Testing: Set up continuous integration (CI) pipelines to run tests on each commit to detect regressions
early.
Test on real devices, as emulators may not simulate real-world conditions like battery usage or network fluctuations.
Data Storage: Store sensitive data like passwords or tokens using EncryptedSharedPreferences or Android
Keystore.
Network Security: Use HTTPS for secure network communication. Verify SSL certificates and avoid using
HTTP.
Permissions: Always follow principle of least privilege—request only the permissions that are essential for your
app to function.
Use clear and consistent naming conventions for classes, methods, variables, and resources.
Use camelCase for variables and methods, and PascalCase for class names.
Use resource directories properly (like res/drawable, res/values, etc.) to ensure assets are organized.
Request only the permissions your app needs to function, as over-requesting permissions can lead to privacy
concerns and users rejecting the app.
For runtime permissions (introduced in Android 6.0), request permissions only when needed, and provide context
on why the permission is necessary.
Leverage Firebase for real-time databases, push notifications, authentication, crash reporting, and more.
Integrate Google Play Services for features like Google Maps, Analytics, and In-App Billing.
Use Android App Bundles to split your app into smaller APKs for different device configurations.
Minimize the use of resources, remove unused assets, and ensure that third-party libraries are required and not too
bulky.
Make sure your app is accessible to users with disabilities. Use features like TalkBack (screen reader) and provide
alternative text for images.
Test your app using Accessibility Scanner and ensure that color contrast is sufficient and that the app can be
navigated using assistive technologies.
Android Activity Lifecycle
The Activity class
defines the following call backs i.e. events. You don't need to implement all the callbacks
methods. However, it's important that you understand each one and implement those that
ensure your app behaves the way users expect.
Sr.No Callback & Description
1 onCreate()
This is the first callback and called when the activity is first created.
onStart()
2
This callback is called when the activity becomes visible to the user.
onResume()
3
This is called when the user starts interacting with the application.
onPause()
4 The paused activity does not receive user input and cannot execute any code and call ed
when the c activity is being resumed.
onStop()
5
This callback is called when the activity is no longer visible.
onDestroy()
6
This callback is called before the activity is destroyed by the system.
onRestart()
This callback is called when the activity restarts after stopping it.
Android tools
Android development is supported by various tools that help developers build, test, and optimize
their applications. Here’s a list of important Android tools along with examples of how they’re
used:
1. Android Studio
Description: The AVD Manager is part of Android Studio and allows you to create and
manage virtual devices (emulators) to test your app.
Key Features:
o Create multiple virtual devices with different screen sizes and Android versions.
o Test your app across different device configurations.
Example: You create a virtual device resembling a Pixel 4 with Android 12 to test your
app’s UI and performance on that device.
Description: ADB is a versatile command-line tool that allows you to communicate with
a device (or emulator) for debugging purposes.
Key Features:
o Install, uninstall, and manage applications on a device.
o Capture logs to help debug issues.
o Interact with the device’s file system.
Example: Use the command adb install app.apk to install an APK file directly onto
your connected device or emulator.
4. Gradle
Description: Gradle is the build automation tool used in Android development. It helps
manage dependencies, compile code, and package the app.
Key Features:
o Manage project dependencies and libraries.
o Build APKs, APK Bundles, and other outputs.
o Handle different build flavors (debug vs. release).
Example: In the build.gradle file, you define the dependencies like implementation
'com.google.firebase:firebase-auth:19.3.2' to include Firebase Authentication
in your app.
5. Firebase
Description: Firebase is a platform from Google that provides various backend services
for Android apps, including real-time databases, authentication, and analytics.
Key Features:
o Firebase Authentication: For managing user sign-ins with email, Google,
Facebook, etc.
o Firebase Firestore: A cloud database to store and sync data in real-time.
o Firebase Crashlytics: To monitor app crashes and exceptions.
Example: Use Firebase Authentication to allow users to sign in using their Google
accounts and Firestore to store user data.
6. ProGuard/R8
Description: ProGuard (and its successor R8) is a tool for optimizing and obfuscating
your Android app code. It removes unused code, reduces the APK size, and makes it
harder to reverse-engineer.
Key Features:
o Minify and obfuscate your code to reduce APK size and improve security.
o Shrink resources by removing unused ones.
Example: Add minifyEnabled true to the build.gradle file to enable R8 to minify
and obfuscate your app’s code when building for release.
7. Lint
Description: Lint is a static code analysis tool built into Android Studio. It scans your
project for potential errors, performance issues, or violations of best practices.
Key Features:
o Identify problems in the app, such as unused resources or incorrect API usage.
o Detect performance issues like inefficient layouts or memory leaks.
Example: Lint will flag when you use deprecated APIs or if your app doesn't meet
Android’s material design guidelines.
8. Android Emulator
Description: The Google Play Console is used to publish, manage, and monitor apps on
the Google Play Store.
Key Features:
o Upload APKs or app bundles.
o Monitor user reviews, app crashes, and user statistics.
o Manage in-app purchases, subscriptions, and monetization.
Example: After developing your app, you use the Google Play Console to publish it to
the Google Play Store, monitor user feedback, and respond to reviews.
10. Crashlytics
Description: Crashlytics is a Firebase service that provides real-time crash reporting and
analytics for Android apps.
Key Features:
o Real-time crash reports with detailed information about exceptions.
o Analytics to help prioritize and fix critical issues.
Example: Use Crashlytics to get detailed reports on why your app crashes when a user
reports an issue, helping you quickly resolve it.
Description: The Android Device Monitor helps you analyze and debug your app on real
devices or emulators.
Key Features:
o Monitor CPU, memory, and network usage.
o View device logs and performance stats.
Example: You use Android Device Monitor to check the heap memory usage of your
app to ensure it doesn’t leak memory and slow down the device.
Description: Dagger and Hilt are dependency injection frameworks used in Android to
simplify the creation and management of dependencies.
Key Features:
o Automatically inject dependencies where they are needed, reducing boilerplate
code.
o Improve code modularity and testability.
Example: Use Hilt to inject a repository into a ViewModel, making the code more
modular and easier to test.
13. Espresso
14. LeakCanary
Prerequisites:
Android Studio installed. If you don't have it, you can download it here.
Basic knowledge of Java or Kotlin (we’ll use Kotlin for this example).
Once the project is created, Android Studio will generate several files for you:
MainActivity.kt (or .java if you chose Java): The main screen of your app.
activity_main.xml: The layout file where you define your app’s UI.
AndroidManifest.xml: The app's configuration file.
xml
CopyEdit
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
</RelativeLayout>
xml
CopyEdit
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello, World!"
android:textSize="24sp"
android:layout_centerInParent="true"/>
This code will place a TextView (a UI element that displays text) in the center of the
screen with the text "Hello, World!" and a text size of 24sp.
1. Open MainActivity.kt (inside the src > main > java folder).
The MainActivity.kt file will look like this by default:
kotlin
CopyEdit
package com.example.helloworld
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
2. The onCreate method is where the app's UI is set up. The line
setContentView(R.layout.activity_main) links the layout we designed in
activity_main.xml to the activity.
Your app should now launch on the emulator or physical device, and you should see a
screen with "Hello, World!" displayed in the center.
You can now modify your app to customize the design and behavior. For example:
kotlin
CopyEdit
val textView: TextView = findViewById(R.id.textView)
textView.text = "Hello, Android!"