Android Architecture:
Android is built in layers, like a cake, where each layer has a specific role. Here’s how it works:
1. Linux Kernel (The Base Layer)
The core of Android, managing hardware like Wi-Fi, Bluetooth, cameras, and memory.
It also handles security, power management, and communication between software and hardware.
2. Hardware Abstraction Layer (HAL) (Bridge between Software & Hardware)
Think of this as a translator between Android software and hardware.
It helps Android talk to the camera, sensors, and other hardware parts without knowing how they work
internally.
3. Native Libraries & Runtime (Support System for Apps)
Libraries (Pre-built tools): Help with graphics, databases, and media playback (like watching videos or
playing music).
Android Runtime (ART): Runs Android apps efficiently and improves performance.
4. Android Framework (The Brain of the System)
A set of tools that apps use to work smoothly.
Includes systems for managing apps, notifications, permissions, location, and UI elements (buttons, text
fields, etc.).
5. Applications (User Layer - What You See & Use)
The top layer where you interact with apps like WhatsApp, YouTube, and Camera.
Apps rely on the Android Framework to function properly.
Each layer plays a role in making Android fast, secure, and user-friendly.
Activity life cycle:
In Android, the Activity Lifecycle refers to the different states an activity goes through from
creation to destruction. Understanding these states is crucial for managing resources efficiently
and ensuring a smooth user experience.
Activity Lifecycle States:
1. onCreate()
o Called when the activity is first created.
o Used for initialization (e.g., setting up UI, initializing variables).
2. onStart()
o Called when the activity becomes visible to the user.
o UI is displayed, but the user may not yet interact with it.
3. onResume()
o Called when the activity is in the foreground and ready for user interaction.
o The user can now interact with the app.
4. onPause()
o Called when the activity is partially block (e.g., a dialog appears).
o Use this to save UI state, pause animations, or release system resources.
5. onStop()
o Called when the activity is no longer visible (e.g., another activity comes to the
foreground).
o Free up resources that are not needed when the activity is not visible.
6. onDestroy()
o Called when the activity is about to be destroyed (either due to the user exiting or
system killing it).
o Use this to clean up resources like database connections.
7. onRestart()
o Called when an activity is being restarted after being stopped.
o Used to reload resources if necessary.
Step-by-Step Guide to Install Android Studio on Windows
1. System Requirements
Before installing Android Studio, ensure your system meets these minimum requirements:
Operating System: Windows 8.1, 10, or 11 (64-bit)
Processor: Intel Core i3 or higher (AMD processors are also supported)
RAM: Minimum 8GB (16GB recommended)
Storage: At least 8GB of free disk space (SSD recommended)
Screen Resolution: 1280 x 800 minimum
Additional Requirements:
Java is included in the Android Studio package, so no need to install it separately.
Virtualization (VT-x) should be enabled in BIOS for faster emulator performance.
2. Download Android Studio
Open a web browser and go to the official Android Studio download page:
➡ https://developer.android.com/studio
Click on Download Android Studio.
Accept the terms and conditions and click Download.
3. Install Android Studio
Step 1: Run the Installer
Locate the downloaded .exe file (e.g., android-studio-setup.exe).
Double-click the file to launch the installation.
Step 2: Setup Wizard
Click Next on the welcome screen.
Select components to install:
Android Studio (required)
Android Virtual Device (AVD) (recommended for running emulators)
Click Next to proceed.
Step 3: Choose Installation Location
Select an installation folder (default is recommended).
Click Next, then Install.
Wait for the installation to complete, then click Finish.
4. Initial Configuration
Step 1: Launch Android Studio
After installation, Android Studio will launch automatically. If not, open it from the Start menu.
Step 2: Setup Wizard
Click Next on the welcome screen.
Choose Standard Installation (recommended) and click Next.
Select your preferred UI theme (Light/Dark).
Click Next, then Finish to download additional components.
Step 3: Install Required SDK Components
The setup wizard will download and install:
Android SDK
Emulator
Necessary build tools
Wait for the installation to complete.
5. Verify Installation
Open Android Studio.
Go to File > Settings > Appearance & Behavior > System Settings > Android SDK.
Ensure the SDKs and tools are installed properly.
6. Create and Run Your First Project
Click Start a New Android Studio Project.
Select Empty Activity and click Next.
Enter project details (Name, Package Name, Language - Kotlin/Java).
Click Finish and wait for the project to load.
Click Run (Green Play Button) to test your app on an emulator or a connected device.
7. Optional: Install Emulator (AVD)
If you want to test apps without a physical device:
Open AVD Manager (Android Virtual Device Manager).
Click Create Virtual Device.
Choose a device model and click Next.
Select a system image (download if needed) and click Next.
Click Finish and start the emulator.
8. Troubleshooting Common Issues
Installation Freezes: Disable antivirus and reinstall.
Emulator Not Starting: Enable virtualization in BIOS.
Gradle Sync Failed: Check internet connection and retry.
Slow Performance: Use an SSD and allocate more RAM to the emulator.
Intent in Android
An Intent in Android is a messaging object used to communicate between different components
of an application, such as activities, services, and broadcast receivers. It allows you to start new
activities, send data, trigger system actions, or communicate between applications.
Explicit Intent (Direct Communication)
Use case: When you know exactly which activity or component to open.
🔹 Think of it like calling a friend directly by dialing their number.
Used for activities within the same app.
Specifies the exact activity to open.
Example:
Starting a new activity after a button click.
Downloading a file.
Open another activity in the same app
Intent intent = new Intent(MainActivity.this, SecondActivity.class);
startActivity(intent);
🔹 You clearly mention the target activity (SecondActivity.class), so Android knows where to go.
2. Implicit Intent (Let Android Decide)
Use case: When you want to perform an action (like opening a webpage or sending an email) but
don’t specify the app.
🔹 Think of it like asking Google Maps for "restaurants near me" and letting it show options.
Used when interacting between activities in different apps.
Does not specify the exact activity to open.
Example:
Showing a location on a map.
Opening a webpage.
Open a webpage in any browser
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("https://www.google.com"));
startActivity(intent);
🔹 Android will show a list of browsers to choose from, instead of a specific one.
Key Parts of an Intent
Action: The task to perform, like ACTION_VIEW or ACTION_EDIT.
Data: The information to work with, such as a URL or a database entry.
What is a Fragment in Android?
A Fragment is a reusable UI component in Android that is part of an Activity. It helps create
dynamic and flexible UI designs, especially for tablets and large screens. A Fragment is a small,
reusable part of an app’s user interface. It works like a mini-Activity inside an Activity.
🔹 Think of a Fragment as a mini-Activity that runs inside an Activity.
🔹 A single Activity can have multiple Fragments at the same time.
A Fragment has its own layout and lifecycle.
It must always be hosted inside an Activity or another Fragment.
It helps create flexible and dynamic UIs, especially for different screen sizes.
Why Use Fragments?
✅ Better UI Design – Easily adjust layouts for different screen sizes.
✅ Reusable Components – One Fragment can be used in multiple Activities.
✅ Flexible Layouts – Different layouts for phones and tablets.
How Fragments Work?
📱 On small screens (phones) – One activity usually takes up the entire screen.
💻 On large screens (tablets) – Multiple Fragments can be shown at the same time.
This makes apps more efficient and adaptable to different devices.
Example of Fragments in Use
✔ In a messaging app, the contacts list can be one Fragment, and the chat window another.
✔ On a phone, they appear on separate screens, but on a tablet, they appear side by side.
Fragment Lifecycle
A Fragment has a lifecycle similar to an Activity:
Method Description
onAttach() Called when the fragment is attached to an activity
onCreate() Fragment is created (initialize variables)
onCreateView() Inflate the layout (UI of the fragment)
onActivityCreated() Activity and fragment UI are ready
onStart() Fragment becomes visible
onResume() Fragment is active and interacting
onPause() Fragment is paused but still visible
onStop() Fragment is no longer visible
onDestroyView() UI is destroyed (but fragment still exists)
onDestroy() Fragment is completely removed
onDetach() Fragment is detached from the activity
Listening for UI Notifications in Android
Introduction
In Android, listening for UI notifications means setting up components to detect and respond to
user interactions, such as button clicks, menu selections, or key presses. This allows apps to react
dynamically to user actions.
Levels of UI Notifications
Android UI interactions occur at two levels:
Activity Level – Detects user actions that affect the entire screen.
View Level – Detects interactions with specific elements like buttons or text fields.
Activity Level Notifications
At the activity level, we can override certain methods to respond to key presses or menu
selections:
onKeyUp(): Triggered when a key is released.
onKeyDown(): Triggered when a key is pressed.
onMenuItemSelected(): Triggered when a menu item is clicked.
onMenuOpened(): Triggered when the menu panel is opened.
View Level Notifications
View-level notifications occur when users interact with specific UI elements like buttons or input
fields. To handle these, we register event listeners.