Android Tutorial

Build native mobile apps with the world's most popular open-source mobile platform

AOSP Kotlin Jetpack Material Design

Table of Contents

1What is Android?

Android is an open-source, Linux-based operating system designed primarily for touchscreen mobile devices like smartphones and tablets. It was developed by a startup of the same name, purchased by Google in 2005, and officially unveiled in 2007.

Unlike iOS (which is closed and exclusive to Apple devices), Android is open-source via the Android Open Source Project (AOSP). This allows device manufacturers (Samsung, Xiaomi, OnePlus, etc.) to customize the OS for their hardware. Android powers billions of devices globally, including watches (Wear OS), TVs (Android TV), cars (Android Auto), and even some laptops.

Key Idea

Android is not just a phone OS; it's a complete software stack for connected devices.

2Features of Android

Android's popularity comes from its rich set of features:

Multitasking

True background processing; run multiple apps simultaneously (e.g., music while browsing).

Customizable Home Screen

Widgets, live wallpapers, and custom launchers for a personalized experience.

Notification System

Rich, expandable, actionable notifications — reply to messages from the shade.

Google Integration

Seamless sync with Gmail, Drive, Photos, Calendar, and Assistant.

Connectivity

GSM, CDMA, LTE, 5G, Wi-Fi, Bluetooth, NFC, and USB support.

Media Support

Wide codecs (MP4, MKV, FLAC) and image formats on diverse hardware.

Hardware Flexibility

Works across screen sizes, ARM/x86 processors, and sensors.

Accessibility

TalkBack, voice access, switch access, and magnification gestures.

Security & Privacy

App sandboxing, runtime permissions, verified boot, biometrics, Play Protect.

3Android Versions (History & Evolution)

Android versions originally had dessert code names (alphabetical order) and numeric API levels. Since Android 10, Google uses version numbers only.

VersionCode NameAPI LevelKey Features Introduced
1.5Cupcake3On-screen keyboard, video recording
4.4KitKat19"OK Google" hotword, immersive mode
5.0Lollipop21Material Design (flat UI), ART runtime
6.0Marshmallow23Runtime permissions, fingerprint support
7.0Nougat24Split-screen mode, bundled notifications
8.0Oreo26Picture-in-picture (PIP), notification channels
9.0Pie28Gesture navigation, Adaptive Battery
10(no dessert)29Dark theme, system-wide privacy controls
1130Conversation notifications, one-time permissions
1231Material You (dynamic color theming)
1333Themed app icons, per-app language settings
1434AI-generated wallpapers, better battery health
1535Partial screen sharing, improved performance
Note: API level is crucial for developers because it determines which features and system behaviors are available.

4Android Architecture (Software Stack)

Android is built as a layered stack. From bottom (hardware) to top (apps):

Layer 5: Applications — System Apps & User Apps (Play Store)
Layer 4: Application Framework — Activity Manager, Window Manager, Package Manager
Layer 3: Android Runtime (ART) & Native Libraries — DEX, SQLite, OpenGL, WebKit
Layer 2: Hardware Abstraction Layer (HAL) — Camera HAL, Audio HAL
Layer 1: Linux Kernel — Drivers, power management, process isolation
1 Linux Kernel

Role: Abstraction layer between hardware and software.

Handles: Drivers (display, camera, audio, Wi-Fi), power management, memory management, and process isolation.

Why Linux? Proven security and driver model.

2 Hardware Abstraction Layer (HAL)

Role: Standard interface for hardware vendors to implement without exposing kernel details.

Example: Camera HAL allows OEMs to write custom camera drivers that still work with Android's camera API.

3 Android Runtime (ART) & Native Libraries

ART: Executes app bytecode (DEX format) ahead-of-time (AOT) or just-in-time (JIT). Replaced Dalvik in Lollipop for better performance.

Native Libraries: C/C++ libraries – libc, OpenGL, SQLite, WebKit, MediaCodec.

4 Application Framework

Role: Provides high-level Java/Kotlin services to apps.

Key Managers: Activity Manager, Window Manager, Package Manager, Notification Manager, Content Providers, Location Manager.

5 Applications

System Apps: Phone, Contacts, Settings, Camera, etc.

User Apps: Downloaded from Play Store. All apps run in isolated sandboxes for security.

5Advantages of Android

AdvantageExplanation
Open SourceVendors can customize; developers can study and modify the OS.
Hardware ChoiceHundreds of devices at all price points (budget to flagship).
Google ServicesFree access to Google Drive, Photos, Maps, Assistant, etc.
CustomizationHome screen launchers, icon packs, third-party keyboards, rooting.
Large Developer CommunityMillions of developers; vast libraries and tools.
Multi-taskingTrue split-screen, floating windows (on some OEMs), background processing.
File System AccessUsers can browse files natively (unlike iOS's restricted access).
Expandable StorageMost devices support microSD cards (flagships are dropping this).
Google Play StoreLargest app catalog with rigorous testing (though some malware exists).

6Android Applications

An Android app is a package (.apk or .aab) containing code, resources (images, layouts), and a manifest.

Common App Types

Native Apps

Written in Kotlin/Java using Android SDK, installed on device.

Hybrid Apps

Web technologies wrapped in a native container (Cordova, Ionic).

Progressive Web Apps

Accessed via browser but can be installed and work offline.

System Apps

Pre-installed with system-level privileges.

App Components (from framework)

Activity Service Broadcast Receiver Content Provider
ComponentPurpose
ActivityOne screen with UI (e.g., login screen).
ServiceBackground task (e.g., music player playing in background).
Broadcast ReceiverResponds to system events (e.g., battery low, SMS received).
Content ProviderManages shared data (e.g., contacts, photos).

Where to run? Emulator (AVD) or physical device.

7Android Ecosystem

The ecosystem extends far beyond phones:

Wear OS

Smartwatches — Samsung Galaxy Watch, Pixel Watch.

Android TV / Google TV

Smart TV platform — Chromecast, Sony, TCL.

Android Auto

Car dashboard experience — maps, music, messages.

Google Play Services

Proprietary APIs for Maps, Location, Firebase (not AOSP).

Third-Party Stores

Amazon Appstore, Samsung Galaxy Store, F-Droid.

OEM Customizations

One UI, OxygenOS, MIUI — features plus fragmentation.

8Android SDK Overview

The Software Development Kit (SDK) is a set of tools and libraries that allow developers to build Android apps.

What's inside the SDK?

ComponentPurpose
Platform Toolsadb (Android Debug Bridge), fastboot, systrace
Build Toolsaapt (Android Asset Packaging Tool), dex, zipalign
Android EmulatorVirtual devices (AVDs) for testing
SDK PlatformsSystem images and libraries for each API level (e.g., API 34 for Android 14)
Support LibrariesJetpack (Room, Navigation, ViewModel)
Command-line toolssdkmanager, avdmanager

How to set up?

  1. Install Android Studio (recommended IDE) – includes SDK by default.
  2. Alternatively, install command-line tools from developer.android.com.
  3. Set environment variable ANDROID_HOME to SDK path.

Key SDK concepts

Minimum SDK
Oldest version supported
Target SDK
Version tested against
Compile SDK
Version you compile with

Essential tools in depth

  • ADB (Android Debug Bridge): Command-line interface to communicate with a device/emulator.
  • Logcat: System logging tool – crucial for debugging crashes and warnings.
  • Layout Inspector: Visual tool in Android Studio to examine UI hierarchy.
  • Profiler: Real-time monitoring of CPU, memory, network, and battery usage.
Bash / ADB# Install an APK on a connected device adb install app.apk # View live system logs (essential for debugging) adb logcat

Hello World code sample (Kotlin)

Kotlinclass MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) // SDK provides AppCompat, Views, etc. } }

9Summary Cheatsheet

TopicKey Takeaway
What is Android?Linux-based open-source OS by Google
Core FeaturesMultitasking, notifications, customization, Google services
VersionsCupcake (1.5) to Android 15; API level is key for devs
ArchitectureLinux Kernel → HAL → ART/Native Libs → Framework → Apps
AdvantagesChoice, customization, large community, open-source
AppsActivities, Services, Broadcast Receivers, Content Providers
EcosystemPhones, watches, TV, Auto, Play Services
SDKTools: ADB, emulator, platform tools; managed via Android Studio

10Next Steps for Learning

1

Install Android Studio and create a "Hello World" project.

2

Explore ADB: Connect a real device (enable Developer Options and USB Debugging).

3

Understand lifecycle: Read about Activity and Fragment lifecycle callbacks.

4

Build a simple UI with ConstraintLayout and handle button clicks.

5

Study Jetpack Compose (modern UI toolkit) – Google's recommended future for Android UI.

Android MCQ Practice

10 Basic MCQs 10 Advanced MCQs

10 Basic Android MCQs

1

What is Android primarily based on?

AWindows Kernel
BLinux Kernel
CmacOS Darwin
DFreeBSD
Explanation: Android is built on the Linux kernel, which handles hardware drivers, memory, and process management.
2

What does AOSP stand for?

AAndroid Open Source Project
BAndroid Operating System Platform
CApplication Open Source Package
DAdvanced OS Programming
Explanation: AOSP is the open-source codebase that device manufacturers can customize for their hardware.
3

Which company currently leads Android development?

AMicrosoft
BApple
CGoogle
DSamsung
Explanation: Google acquired Android Inc. in 2005 and continues to develop the platform and Android Open Source Project.
4

What are the four core Android app components?

AActivity, Service, Broadcast Receiver, Content Provider
BFragment, View, Intent, Adapter
CActivity, Fragment, ViewModel, Repository
DService, Worker, Notification, Database
Explanation: These four components are the building blocks defined by the Android framework for all applications.
5

Which language is Google's preferred choice for Android development?

AJava
BKotlin
CPython
DC++
Explanation: Kotlin is officially recommended by Google since 2019 for new Android projects due to its conciseness and null safety.
6

What is the official IDE for Android development?

AEclipse
BVisual Studio Code
CAndroid Studio
DIntelliJ IDEA Community only
Explanation: Android Studio is built on IntelliJ IDEA and includes the Android SDK, emulator, and build tools.
7

Which runtime executes Android apps since Android 5.0 (Lollipop)?

ADalvik
BART (Android Runtime)
CJVM
DNode.js
Explanation: ART replaced Dalvik and uses ahead-of-time (AOT) and just-in-time (JIT) compilation for better performance.
8

What does API level represent in Android?

AApp store ranking
BInteger version of the Android platform SDK
CNumber of app downloads
DDevice RAM size
Explanation: Each Android version maps to an API level (e.g., Android 14 = API 34). Developers use minSdk and targetSdk in Gradle.
9

Which tool is used to communicate with a connected Android device from the command line?

AADB (Android Debug Bridge)
BGradle
CLog4j
Dnpm
Explanation: ADB is part of the Android SDK platform-tools and is essential for installing apps, debugging, and viewing Logcat.
10

What is Jetpack in Android?

AA collection of libraries and best-practice components
BA physical device accessory
CA replacement for the Linux kernel
DA JavaScript framework
Explanation: Android Jetpack includes libraries like ViewModel, Room, Navigation, WorkManager, and Compose for modern app development.

10 Advanced Android MCQs

1

What is the purpose of the Hardware Abstraction Layer (HAL)?

ABridge framework APIs to device-specific hardware drivers
BRender UI composables
CManage Play Store billing
DCompile Kotlin to bytecode
Explanation: HAL provides standard interfaces so the Android framework can work across different device hardware from various manufacturers.
2

Why does ViewModel survive configuration changes like screen rotation?

AIt is stored in SharedPreferences automatically
BIt outlives the Activity/Fragment and is scoped to the lifecycle owner
CIt runs on a separate process
DIt is saved in the AndroidManifest
Explanation: ViewModel is retained across configuration changes until the Activity is finished, unlike Activity instances which are recreated.
3

What is the difference between explicit and implicit Intents?

AExplicit targets a specific component; implicit lets the system choose
BExplicit is for Services only; implicit is for Activities only
CThere is no difference
DExplicit requires internet permission
Explanation: Explicit Intents specify the exact class (e.g., open DetailActivity). Implicit Intents declare an action (e.g., ACTION_VIEW a URL) and the system resolves the target.
4

In MVVM architecture, what is the role of the Repository?

ADisplay UI layouts
BSingle source of truth coordinating remote and local data
CHandle touch events only
DReplace the AndroidManifest
Explanation: The Repository abstracts data sources (API, Room, cache) so ViewModels don't need to know where data comes from.
5

When should you use WorkManager instead of a foreground Service?

ADeferrable, guaranteed background work with constraints
BReal-time music playback visible to the user
CUI rendering at 60fps
DParsing XML layouts
Explanation: WorkManager is ideal for sync, uploads, and periodic tasks. Foreground Services are for user-visible long-running tasks like GPS tracking or music.
6

What is Jetpack Compose primarily used for?

ADeclarative UI built with Kotlin composable functions
BDatabase migrations
CPush notification delivery
DSigning release APKs
Explanation: Compose replaces XML layouts with @Composable functions that describe UI and recompose when state changes.
7

What does R8 do in a release build?

AShrinks, obfuscates, and optimizes code
BRuns unit tests automatically
CGenerates app icons
DUploads to Play Store
Explanation: R8 (successor to ProGuard) removes unused code, renames classes/methods, and reduces APK/AAB size while obfuscating the codebase.
8

What is the main advantage of Room over raw SQLiteOpenHelper?

ACompile-time SQL verification and less boilerplate
BIt stores data in the cloud automatically
CIt replaces Retrofit for networking
DIt only works with Java, not Kotlin
Explanation: Room provides DAOs, entity mapping, Flow/LiveData integration, and migrations with compile-time query checking.
9

Why observe LiveData with viewLifecycleOwner in Fragments?

APrevents crashes when the Fragment view is destroyed but Activity remains
BImproves network speed
CRequired for ProGuard
DEnables dark mode
Explanation: Using the Fragment's view lifecycle ensures observers are removed when the view is destroyed, avoiding updates to destroyed UI.
10

What format is required for uploading new apps to Google Play?

AAndroid App Bundle (.aab)
BUnsigned APK only
CZIP of source code
DDocker image
Explanation: Google Play requires AAB for new apps. Play generates optimized APKs per device configuration from the bundle.

15 Interview Questions & Answers

Easy Medium Hard
1What is Android?easy
Answer: Android is an open-source, Linux-based operating system designed primarily for mobile devices. It is maintained by Google through the Android Open Source Project (AOSP) and powers smartphones, tablets, watches, TVs, and more.
2What are the four main components of an Android app?easy
Answer: Activities (UI screens), Services (background work), Broadcast Receivers (system/app event listeners), and Content Providers (structured data sharing between apps).
3What is an Activity lifecycle?easy
Answer: The Activity lifecycle is a set of callback methods — onCreate(), onStart(), onResume(), onPause(), onStop(), onDestroy() — that manage an Activity's state as the user navigates in and out of the screen.
4What is the difference between minSdk and targetSdk?easy
Answer: minSdk is the lowest Android version your app supports. targetSdk tells the system which API level you tested against — newer behavior changes apply at the target level.
5Why is Kotlin preferred over Java for new Android projects?easy
Answer: Kotlin is concise, has built-in null safety, supports coroutines for async work, is fully interoperable with Java, and is officially recommended by Google for Android development.
6What is an Intent in Android?medium
Answer: An Intent is a messaging object used to request an action — starting an Activity, launching a Service, delivering a Broadcast, or sharing data between components within or across apps.
7Explain the Android software stack layers.medium
Answer: From bottom to top: Linux Kernel → Hardware Abstraction Layer (HAL) → Native Libraries & ART → Android Framework (APIs) → Applications. Each layer abstracts the one below it.
8What is the difference between Fragment and Activity?medium
Answer: An Activity represents a single screen with its own lifecycle. A Fragment is a reusable UI portion hosted inside an Activity, enabling flexible layouts like master-detail on tablets and bottom navigation with multiple screens.
9What is MVVM and how does it apply to Android?medium
Answer: Model-View-ViewModel separates UI (View) from logic (ViewModel) and data (Model/Repository). ViewModel exposes LiveData or StateFlow; the View observes it. This survives rotation and improves testability.
10What are coroutines and why use them on Android?medium
Answer: Kotlin coroutines simplify asynchronous programming by allowing sequential-looking code for network calls, database access, and background work without blocking the main thread or using callback hell.
11What is the purpose of RecyclerView?medium
Answer: RecyclerView efficiently displays large scrollable lists by recycling ViewHolder items off-screen. It supports different layout managers, item animations, and DiffUtil for efficient list updates.
12How does Android handle runtime permissions?medium
Answer: Dangerous permissions (camera, location, storage) must be declared in the manifest and requested at runtime via ActivityResultContracts.RequestPermission(). The user can grant or deny each permission.
13What is the difference between Serializable and Parcelable?hard
Answer: Both pass data between components. Parcelable is Android-optimized — faster and more efficient for IPC (Intents, Bundles). Serializable is Java-standard but slower due to reflection. Prefer Parcelable or Kotlin @Parcelize.
14How would you prevent memory leaks in an Android app?hard
Answer: Avoid static Activity references, unregister listeners in lifecycle callbacks, use lifecycle-aware components (ViewModel, LiveData), scope coroutines to viewModelScope/lifecycleScope, use LeakCanary in debug, and null Fragment binding in onDestroyView.
15Describe the process of publishing an app to Google Play.hard
Answer: Create a Play Console account, generate a signed App Bundle (AAB), complete store listing and policy forms (privacy, content rating, data safety), upload to a testing track, verify on devices, then roll out to production with staged rollout recommended.