■ ANDROID APPLICATION DEVELOPMENT
Android OS & Architecture | Activities & UI Design | Advanced UI | Toast | Menu | Dialog | List & Adapters |
SQLite Database
■ Exam Gujarat Police Wireless PSI / Technical Operator
■ Subject Computer Engineering (Part B — Technical)
■ Importance HIGH | Expected 8–12 Questions from this Topic
■ Chapters 7 Chapters | Complete Theory + Code Coverage
Prepared exclusively for the Wireless PSI / Technical Operator Government Exam. All concepts are exam-focused,
concise, and aligned with the official syllabus.
■ TABLE OF CONTENTS
Chapter 1 — Android OS — Concepts & Overview
■ 1.1 What is Android?
■ 1.2 History & Versions of Android
■ 1.3 Features of Android OS
■ 1.4 Android vs iOS Comparison
■ 1.5 Android SDK & Development Tools
■ 1.6 ADB — Android Debug Bridge
Chapter 2 — Android Architecture
■ 2.1 Android Software Stack — 5 Layers
■ 2.2 Linux Kernel Layer
■ 2.3 Hardware Abstraction Layer (HAL)
■ 2.4 Android Runtime (ART) & Dalvik VM
■ 2.5 Native C/C++ Libraries
■ 2.6 Java API Framework
■ 2.7 System Apps Layer
Chapter 3 — Android Activities and UI Design
■ 3.1 What is an Activity?
■ 3.2 Activity Lifecycle — All States & Methods
■ 3.3 Activity Stack & Back Stack
■ 3.4 Intent — Explicit & Implicit
■ 3.5 UI Layout Files — XML
■ 3.6 Layout Types — Linear, Relative, Constraint, Frame, Table, Grid
■ 3.7 [Link]
■ 3.8 Project Structure
Chapter 4 — Advanced UI Programming
■ 4.1 Common View Widgets
■ 4.2 TextView, EditText, Button
■ 4.3 ImageView, ImageButton
■ 4.4 CheckBox & RadioButton
■ 4.5 Spinner (Dropdown)
■ 4.6 ProgressBar & SeekBar
■ 4.7 Fragments — Introduction
■ 4.8 RecyclerView Overview
Chapter 5 — Toast, Menu & Dialog
■ 5.1 Toast — Types and Usage
■ 5.2 Snackbar
■ 5.3 Options Menu
■ 5.4 Context Menu
■ 5.5 Popup Menu
■ 5.6 AlertDialog
■ 5.7 ProgressDialog
■ 5.8 DatePickerDialog & TimePickerDialog
■ 5.9 Custom Dialog
Chapter 6 — List and Adapters
■ 6.1 What is an Adapter?
■ 6.2 ListView
■ 6.3 ArrayAdapter
Wireless PSI / TO Exam Prep | Android Application Development Page 2
■ 6.4 BaseAdapter
■ 6.5 Custom ListView with Custom Adapter
■ 6.6 RecyclerView & [Link]
■ 6.7 ViewHolder Pattern
■ 6.8 GridView
Chapter 7 — Working with Database — SQLite
■ 7.1 SQLite in Android
■ 7.2 SQLiteOpenHelper
■ 7.3 Creating Database & Tables
■ 7.4 CRUD Operations
■ 7.5 ContentValues
■ 7.6 Cursor & Reading Data
■ 7.7 Complete CRUD Example
■ 7.8 Room Database (Introduction)
Quick Revision — Master Cheatsheet & Top 12 Exam Tips
Wireless PSI / TO Exam Prep | Android Application Development Page 3
Chapter 1
Android OS — Concepts & Overview
■ 1.1 What is Android?
Android is an open-source, Linux-based mobile operating system developed by Google. It is designed primarily
for touchscreen mobile devices such as smartphones and tablets. Android is the world's most widely used
mobile OS.
Andy Rubin is widely recognized as the Father of Android. He founded Android Inc. in 2003
Parameter Details
Developer Google LLC (originally Android Inc., acquired by Google in 2005)
First Release September 23, 2008 (Android 1.0)
Based On Linux Kernel
License Open Source — Apache License 2.0 (most parts)
Programming Language Java, Kotlin (official), C/C++ (NDK)
Architecture ARM, x86, MIPS
Market Share ~72% of global mobile OS market (2024)
App Store Google Play Store
App Format .apk (Android Package) / .aab (Android App Bundle)
IDE Android Studio (official IDE by Google)
■ 1.2 Android Versions History
Version Name Year API Level Key Feature
Android 1.0 — 2008 1 First release — basic apps
Android 2.3 Gingerbread 2010 9-10 NFC support, improved SIP
Android 4.0 Ice Cream Sandwich 2011 14-15 Unified phone/tablet UI, Face Unlock
Android 4.4 KitKat 2013 19-20 Performance improvements, ART preview
Android 5.0 Lollipop 2014 21-22 Material Design, ART replaces Dalvik
Android 6.0 Marshmallow 2015 23 Runtime permissions, Doze mode
Android 7.0 Nougat 2016 24-25 Multi-window, improved notifications
Android 8.0 Oreo 2017 26-27 Picture-in-Picture, notification channels
Android 9 Pie 2018 28 Adaptive battery, gesture navigation
Android 10 Q (no name) 2019 29 Dark theme, foldables support
Android 11 R 2020 30 Bubbles, conversation notifications
Wireless PSI / TO Exam Prep | Android Application Development Page 4
Version Name Year API Level Key Feature
Android 12 S 2021 31-32 Material You, privacy dashboard
Android 13 T (Tiramisu) 2022 33 Per-app language, themed icons
U (Upside Down
Android 14 2023 34 Health Connect, large screen
Cake)
V (Vanilla Ice
Android 15 2024 35 Predictive back, privacy improvements
Cream)
✎ EXAM TIP: Android versions: Lollipop(5.0)=Material Design+ART. Marshmallow(6.0)=runtime
permissions. Oreo(8.0)=notification channels. Android 10+ = no dessert names. API level = version
number!
■ 1.3 Features of Android OS
Feature Description
Open Source Source code available under Apache License — free to use, modify, distribute
Linux Kernel Based on Linux — provides process management, memory management, security
Multitasking Run multiple apps simultaneously — background services
Multi-touch Supports multi-finger touch gestures — pinch, zoom, swipe
Rich UI Material Design guidelines — smooth animations, consistent UI
Connectivity WiFi, Bluetooth, NFC, 4G/5G, USB — comprehensive connectivity
Google Services Deep integration with Google Maps, Gmail, Play Store, Drive
App Store Google Play Store — millions of apps — easy distribution
Media Support Supports MP3, AAC, H.264, VP8, JPEG, PNG, GIF and more
Storage Internal storage + external SD card support
Security App sandbox, permissions model, encryption, Play Protect
Developer Friendly Android Studio, ADB, emulator, comprehensive SDK and APIs
Customization Highly customizable — OEM skins (Samsung One UI, Xiaomi MIUI) MIUI , ColorOS ,
OxygenOS , SailfishOS ,
Ubuntu Touch, Maemo,
Virtual Machine ART (Android Runtime) executes Dalvik bytecode efficiently
OneUI/Tizer Samsung,
KaiOS , IndusOS ,
HarmonyOS,
■ 1.4 Android Development Tools FunTouchOS , TeslaOS ,
iOS, Nokia Symbian
Tool Purpose
Android Studio Official IDE by Google — replaced Eclipse + ADT plugin in 2013
Android SDK Software Development Kit — libraries, tools, APIs for Android development
ADB (Android Debug
Command-line tool to communicate with emulator/device for debugging
Bridge)
Wireless PSI / TO Exam Prep | Android Application Development Page 5
Tool Purpose
AVD Manager Android Virtual Device Manager — create and manage emulators
Gradle Build automation system — compiles and packages Android apps (.apk/.aab)
DDMS Dalvik Debug Monitor Server — now replaced by Android Profiler in Android Studio
ProGuard / R8 Code shrinker and obfuscator — reduces APK size and protects code
Android Emulator Virtual device to test apps without physical hardware
Firebase Google's mobile platform — analytics, crash reporting, authentication, cloud DB
✎ EXAM TIP: Android Studio = official IDE (replaced Eclipse in 2013). ADB = Android Debug Bridge =
command-line debugging. Gradle = build system. AVD = Android Virtual Device (emulator)!
Wireless PSI / TO Exam Prep | Android Application Development Page 6
Chapter 2
Android Architecture
■ 2.1 Android Software Stack — 5 Layers
Android Architecture (Top to Bottom): Layer 5: System Applications (Gmail, Camera, Browser, Phone, Contacts)
Layer 4: Java API Framework (Activity Manager, View System, Content Providers, etc.) Layer 3: Native C/C++
Libraries + Android Runtime (ART) Layer 2: Hardware Abstraction Layer (HAL) Layer 1: Linux Kernel (Drivers,
Security, Memory, Power Management)
■ 2.2 Layer-wise Explanation
Layer Components Key Role
Display driver, Camera driver, Bluetooth, Foundation — hardware abstraction,
Linux Kernel (Layer 1) WiFi, USB, Power Management, Memory process/memory management, security,
Management, Binder IPC networking
HAL — Hardware
Audio HAL, Bluetooth HAL, Camera HAL, Standard interface between hardware and Java
Abstraction Layer (Layer
Sensors HAL, Graphics HAL API framework — OEM implements HAL
2)
Android Runtime + ART, Core Java Libraries, WebKit, OpenGL ART executes .dex bytecode. Native C/C++
Native Libraries (Layer 3) ES, SQLite, Media Framework, libc libraries provide core services
Activity Manager, Window Manager, Content
Java API Framework Providers, View System, Package Manager, Building blocks for Android apps — access via
(Layer 4) Notification Manager, Location Manager, Java/Kotlin APIs
Resource Manager
System Applications Phone, SMS, Email, Browser, Camera, Pre-installed apps using the same framework
(Layer 5) Calendar, Contacts, Settings APIs as third-party apps
■ 2.3 Android Runtime (ART) & Dalvik VM Virtual Machine (VM)
Feature Dalvik VM (Old) ART (Current — Android 5.0+)
Compilation JIT — Just-In-Time (at runtime) AOT — Ahead-Of-Time (at install time)
Performance Slower (JIT overhead) Faster (pre-compiled native code)
Battery Higher consumption Lower consumption
Install Time Fast Slightly slower (compiles at install)
App Size Smaller Larger (includes compiled code)
Bytecode format .dex (Dalvik Executable) .dex → compiled to native code
Introduced Android 1.0 Android 5.0 Lollipop (replaced Dalvik)
Wireless PSI / TO Exam Prep | Android Application Development Page 7
✎ EXAM TIP: ART replaced Dalvik in Android 5.0 (Lollipop). ART = AOT compilation = faster execution.
Dalvik = JIT. Both use .dex bytecode format. ART = better performance and battery life!
■ 2.4 Key Framework Components
Component Function
Activity Manager Manages Activity lifecycle — starts, stops, resumes activities
Window Manager Manages windows and display — renders UI to screen
Content Providers Enables data sharing between applications (contacts, media store)
View System UI building blocks — all widgets (TextView, Button, etc.) are Views
Package Manager Manages installed applications — install, remove, query app info
Notification Manager Manages status bar notifications and alerts
Location Manager Provides GPS and network-based location services
Resource Manager Manages non-code resources — layouts, strings, images, styles
Telephony Manager Access to telephony services — call state, network info
Wireless PSI / TO Exam Prep | Android Application Development Page 8
Chapter 3
Android Activities and UI Design
■ 3.1 What is an Activity?
An Activity is a single screen with a user interface in an Android app. Every screen in an Android application is
represented by an Activity. It acts as the entry point for user interaction.
• An Activity represents one screen / one window of the app
• Activities contain UI elements (Views) arranged in layouts
• Apps typically have multiple activities — each is a separate class extending Activity or AppCompatActivity
• Activities are declared in [Link]
• Example: SplashActivity, LoginActivity, MainActivity, ProfileActivity
■ 3.2 Activity Lifecycle — Complete
Activity Lifecycle States & Callback Methods (in order): onCreate() → Activity created — initialize UI, set content
view, bind data onStart() → Activity becomes visible to user onResume() → Activity is in foreground, user can
interact — RUNNING state onPause() → Another activity partially covers this one — release resources onStop()
→ Activity no longer visible — save state onRestart() → Called after onStop() when activity comes back
onDestroy() → Activity is being destroyed — final cleanup
Method When Called What to Do Here
onCreate() Activity first created — initial setup setContentView(), find views, initialize objects, set listeners
onStart() Activity becoming visible Start animations, register BroadcastReceiver
Activity in foreground, fully
onResume() Start camera, play media, resume paused operations
interactive
Activity partially hidden (dialog,
onPause() Pause animations, save unsaved data, release camera
new activity)
onStop() Activity completely hidden Save to database, stop heavy computations
Activity returning from stopped
onRestart() Refresh data that may have changed
state
Activity being permanently
onDestroy() Release all resources, close connections
destroyed
✎ EXAM TIP: Activity lifecycle order: onCreate→onStart→onResume
(visible+interactive)→onPause→onStop→onDestroy. Most code goes in onCreate(). Save state in
onPause()/onStop(). Always call [Link]() first!
■ 3.3 Intent — Communication Between Activities
An Intent is a messaging object used to request an action from another component — start an activity, start a
service, or deliver a broadcast.
Wireless PSI / TO Exam Prep | Android Application Development Page 9
Intent Type Description Example
Directly specify the target component Intent i = new Intent(this, [Link]);
Explicit Intent
(class name) — used within same app startActivity(i);
Declare general action — Android finds Intent i = new Intent(Intent.ACTION_VIEW,
Implicit Intent
appropriate app to handle it [Link]("[Link] startActivity(i);
Passing Data Between Activities:
// Sending activity: Intent intent = new Intent(this, [Link]);
[Link]("username", "Rahul"); [Link]("age", 25); startActivity(intent); //
Receiving activity (SecondActivity): String name = getIntent().getStringExtra("username");
int age = getIntent().getIntExtra("age", 0);
✎ EXAM TIP: Explicit intent = specify class directly = within app. Implicit intent = specify action = system
chooses app (browser, camera, maps). Use putExtra() to pass data, getIntent().getXxxExtra() to receive!
■ 3.4 UI Layout Types
Layout Description Best Use
Arranges children in a single row (horizontal)
LinearLayout or column (vertical). Uses weight for Simple forms, rows/columns of buttons
proportional sizing.
Positions children relative to each other or
RelativeLayout parent — alignParentTop, toRightOf, below, Complex UI where elements need precise positioning
etc.
Most flexible — positions using constraints to
Any complex layout — recommended for all new
ConstraintLayout parent or other views. Best performance.
development
Default in new projects.
Stacks children on top of each other — only Fragment containers, overlapping views, splash
FrameLayout
one visible at a time typically. screens
Arranges children in rows and columns like
TableLayout Form layouts, grids of data
an HTML table.
Divides space into grid — children placed in
GridLayout Calculator UI, icon grids
specific rows and columns.
Single child view that can scroll vertically
ScrollView Long forms, content pages
when content exceeds screen.
Advanced container for Material Design
CoordinatorLayout Toolbar collapsing, FAB positioning
animations and interactions.
✎ EXAM TIP: ConstraintLayout = best performance = default for new projects. LinearLayout = simplest.
RelativeLayout = relative positioning. FrameLayout = fragment containers. All layouts extend
ViewGroup!
■ 3.5 [Link]
Wireless PSI / TO Exam Prep | Android Application Development Page 10
The [Link] is the most important configuration file in every Android app. It must be in the root of
the app project.
Manifest Element Purpose
Root element — package name, version code, version name
App-wide settings — icon, label, theme, backup
Register each Activity — name, intent-filter, label, theme
Define what intents an activity can handle — MAIN+LAUNCHER = app entry
Register background Service components
Register BroadcastReceiver components
Register ContentProvider components
Declare permissions needed — INTERNET, CAMERA, STORAGE, etc.
Declare hardware features needed — camera, GPS, NFC
Minimum and target SDK versions
Example [Link] snippet:
<manifest package="[Link]"> <uses-permission
android:name="[Link]"/> <application android:icon="@mipmap/ic_launcher"
android:label="My App"> <activity android:name=".MainActivity"> <intent-filter> <action
android:name="[Link]"/> <category
android:name="[Link]"/> </intent-filter> </activity>
</application> </manifest>
✎ EXAM TIP: [Link] must declare ALL activities, services, receivers. MAIN+LAUNCHER in
intent-filter = app launcher entry point. uses-permission = request device permissions!
■ 3.6 Android Project Structure
Folder / File Contents
app/src/main/java/ Java/Kotlin source files — Activity classes, utilities
app/src/main/res/layout/ XML layout files — activity_main.xml, fragment layouts
app/src/main/res/values/ [Link] (text), [Link], [Link], [Link]
app/src/main/res/drawable/ Image resources — PNG, XML drawables, icons
app/src/main/res/mipmap/ App launcher icons (different DPI sizes)
app/src/main/res/menu/ XML menu resource files
app/src/main/[Link] App configuration — activities, permissions, features
app/[Link] Module-level build config — dependencies, SDK versions
[Link] (project) Project-level build config — repositories, plugins
[Link] Gradle build properties
Wireless PSI / TO Exam Prep | Android Application Development Page 11
Folder / File Contents
app/src/main/assets/ Raw files — HTML, fonts, JSON — accessed via AssetManager
Wireless PSI / TO Exam Prep | Android Application Development Page 12
Chapter 4
Advanced UI Programming
■ 4.1 Common View Widgets
Widget XML Tag Key Attributes Common Use
text, textSize, textColor, textStyle,
TextView TextView Display text labels
gravity
hint, inputType, maxLength,
EditText EditText User text input
imeOptions
Button Button text, onClick, background, enabled Clickable button
ImageView ImageView src, scaleType, adjustViewBounds Display images
CheckBox CheckBox text, checked, onCheckedChanged Boolean toggle
RadioButton RadioButton text, checked (in RadioGroup) Single selection from group
RadioGroup RadioGroup orientation, onCheckedChanged Container for RadioButtons
Spinner Spinner entries, prompt, onItemSelected Dropdown selection
ProgressBar ProgressBar progress, max, indeterminate Show progress/loading
SeekBar SeekBar progress, max, onProgressChanged Slider control
Switch Switch checked, text, onCheckedChanged Toggle switch (on/off)
ToggleButton ToggleButton textOn, textOff, checked Two-state toggle button
ScrollView ScrollView (wraps single child) Vertical scrolling container
WebView WebView loadUrl(), loadData() Display web content in app
■ 4.2 Common UI Code Patterns
Finding Views and Setting Click Listeners:
// In onCreate() of Activity: Button btnSubmit = findViewById([Link]); EditText
etName = findViewById([Link]); TextView tvResult = findViewById([Link]); // Set
click listener: [Link](new [Link]() { @Override public
void onClick(View v) { String name = [Link]().toString(); [Link]("Hello, "
+ name); } }); // Lambda (modern Java / Kotlin): [Link](v -> {
[Link]("Hello, " + [Link]()); });
■ 4.3 Fragments
A Fragment is a reusable portion of UI within an Activity. Fragments have their own lifecycle. An Activity can
contain multiple fragments.
Wireless PSI / TO Exam Prep | Android Application Development Page 13
Fragment Feature Description
Reusability Same fragment used in multiple activities — code reuse
Modular UI Break complex UI into manageable, independent pieces
Back Stack Fragment transactions added to back stack — back button navigation
Lifecycle Has own lifecycle tied to hosting activity
FragmentManager Manages fragments — add, replace, remove, find by tag
FragmentTransaction Batch fragment operations — add(), replace(), commit()
Fragment Arguments Pass data to fragments using Bundle — setArguments()
Communication Fragment → Activity via interface; Activity → Fragment via findFragmentById()
✎ EXAM TIP: Fragment = reusable UI piece within Activity. Fragment has own lifecycle.
FragmentManager manages fragments. setArguments(bundle) to pass data. Used in tablets for
multi-pane layouts!
Wireless PSI / TO Exam Prep | Android Application Development Page 14
Chapter 5
Toast, Menu and Dialog
■ 5.1 Toast
A Toast is a small popup message that appears briefly on screen and automatically disappears. It does NOT
require user interaction.
Toast Parameter Options
Duration Toast.LENGTH_SHORT (2 seconds) or Toast.LENGTH_LONG (3.5 seconds)
Position Default bottom center; can be customized with setGravity()
Content Text only (basic) or custom View (custom toast)
Blocking Non-blocking — app continues running while toast is shown
Toast Code Examples:
// Basic Toast: [Link](this, "Hello World!", Toast.LENGTH_SHORT).show(); // Long
Toast: [Link](getApplicationContext(), "Saved!", Toast.LENGTH_LONG).show(); // Toast
with custom position: Toast toast = [Link](this, "Top Center!", Toast.LENGTH_SHORT);
[Link]([Link] | Gravity.CENTER_HORIZONTAL, 0, 100); [Link]();
✎ EXAM TIP: Toast = brief non-interactive popup. LENGTH_SHORT = 2s. LENGTH_LONG = 3.5s. Always
call .show() — forgetting .show() is a common mistake! Toast cannot receive user clicks!
■ 5.2 Types of Menus
Menu Type Description How to Create When It Appears
Primary menu of an activity — Override
User taps 3-dot overflow icon or
Options Menu shown in ActionBar/toolbar as onCreateOptionsMenu(), inflate
menu hardware button
3-dot overflow menu [Link].menu_main
Floating menu that appears when Override
User long-presses registered
Context Menu user long-presses (long-clicks) a onCreateContextMenu() +
view
view registerForContextMenu(view)
Small menu anchored to a specific
Create PopupMenu object, Triggered by button click or other
Popup Menu view — appears below/above
inflate menu, show() action
anchor
Options Menu Code:
// res/menu/menu_main.xml: <menu xmlns:android="..."> <item android:id="@+id/action_settings"
android:title="Settings" android:showAsAction="never"/> <item
android:id="@+id/action_search" android:title="Search" android:icon="@drawable/ic_search"
android:showAsAction="ifRoom"/> </menu> // In Activity: @Override public boolean
onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate([Link].menu_main, menu); return
true; } @Override public boolean onOptionsItemSelected(MenuItem item) { if ([Link]()
== [Link].action_settings) { // Handle settings click return true; } return
Wireless PSI / TO Exam Prep | Android Application Development Page 15
[Link](item); }
✎ EXAM TIP: Options Menu = toolbar/ActionBar menu. Context Menu = long-press menu. Popup Menu =
anchored to view. Menu items defined in XML res/menu/ folder. showAsAction: always/ifRoom/never!
■ 5.3 Dialogs
Dialog Type Class Use Key Methods
Yes/No confirmations, setTitle(), setMessage(), setPositiveButton(),
Alert Dialog [Link]
information messages setNegativeButton(), setNeutralButton()
Show progress — use
ProgressDialog setMessage(), setProgressStyle(),
Progress Dialog ProgressBar in custom
(deprecated) show()/dismiss()
dialog instead
Date Picker Dialog DatePickerDialog Let user select a date [Link]
Time Picker Dialog TimePickerDialog Let user select a time [Link]
Custom Dialog Dialog / AlertDialog Any custom UI in dialog setContentView() with custom layout
AlertDialog Example:
[Link] builder = new [Link](this); [Link]("Confirm
Delete") .setMessage("Are you sure you want to delete?") .setPositiveButton("Yes", (dialog,
which) -> { // User clicked Yes deleteRecord(); }) .setNegativeButton("No", (dialog, which)
-> { [Link](); }) .setIcon([Link].ic_dialog_alert) .show();
✎ EXAM TIP: [Link] pattern: create builder, set title/message/buttons, call show().
setPositiveButton = OK/Yes. setNegativeButton = Cancel/No. setNeutralButton = third option. Always call
show()!
Wireless PSI / TO Exam Prep | Android Application Development Page 16
Chapter 6
List and Adapters
■ 6.1 What is an Adapter?
An Adapter acts as a bridge between data source and UI view (ListView/RecyclerView). It converts each data
item into a View that can be displayed.
Data Source (Array/List/Database) → ADAPTER → ListView/RecyclerView (UI)
Adapter Type Data Source View Use Case
ArrayAdapter Array or ArrayList ListView, Spinner Simple list of strings/objects
BaseAdapter Custom data ListView Custom list items — extend and override getView()
SimpleCursorAdapter Database Cursor ListView Database query results
[Link] List RecyclerView Modern replacement for ListView — highly optimized
CursorAdapter Cursor ListView Database-backed lists
■ 6.2 ListView with ArrayAdapter
XML Layout (activity_main.xml):
<ListView android:id="@+id/listView" android:layout_width="match_parent"
android:layout_height="match_parent"/>
Java Code:
ListView listView = findViewById([Link]); // String array data source: String[] fruits
= {"Apple", "Banana", "Mango", "Orange", "Grapes"}; // ArrayAdapter with built-in
simple_list_item_1 layout: ArrayAdapter<String> adapter = new ArrayAdapter<>( this,
[Link].simple_list_item_1, fruits ); [Link](adapter); // Item click
listener: [Link]((parent, view, position, id) -> { String selected =
fruits[position]; [Link](this, "Selected: " + selected, Toast.LENGTH_SHORT).show();
});
✎ EXAM TIP: ArrayAdapter = simplest adapter for ListView. Three params: context, layout
(simple_list_item_1), data array. setOnItemClickListener for click events. position = index of clicked item!
■ 6.3 Custom Adapter with BaseAdapter
Custom Adapter — 4 methods to override:
Method Purpose
getCount() Return total number of items in data source
getItem(int position) Return data item at given position
Wireless PSI / TO Exam Prep | Android Application Development Page 17
Method Purpose
getItemId(int position) Return unique ID for item at position (often return position)
getView(int position, View
convertView, ViewGroup Return View for each item — inflate layout, bind data
parent)
Custom Adapter Code:
public class FruitAdapter extends BaseAdapter { Context context; String[] names; int[]
images; LayoutInflater inflater; public FruitAdapter(Context ctx, String[] n, int[] img) {
context = ctx; names = n; images = img; inflater = [Link](context); } @Override
public int getCount() { return [Link]; } @Override public Object getItem(int pos) {
return names[pos]; } @Override public long getItemId(int pos) { return pos; } @Override
public View getView(int pos, View convertView, ViewGroup parent) { if (convertView == null)
convertView = [Link]([Link].list_item, parent, false); TextView tvName =
[Link]([Link]); ImageView ivIcon =
[Link]([Link]); [Link](names[pos]);
[Link](images[pos]); return convertView; } }
■ 6.4 RecyclerView — Modern List View
RecyclerView is the modern, more flexible replacement for ListView. It recycles (reuses) view holders for better
performance.
RecyclerView Component Purpose
RecyclerView The view itself — placed in XML layout
[Link] Creates ViewHolder objects and binds data
[Link] Holds references to views for one list item — avoids repeated findViewById()
Controls how items are arranged (LinearLayoutManager, GridLayoutManager,
LayoutManager
StaggeredGridLayoutManager)
ItemDecoration Add dividers, spacing between items
ItemAnimator Animate add/remove/change operations
RecyclerView Adapter Structure:
public class MyAdapter extends [Link]<[Link]> { List<String>
data; // ViewHolder: holds references to views for one item static class ViewHolder extends
[Link] { TextView tvName; ViewHolder(View v) { super(v); tvName =
[Link]([Link]); } } @Override // Create new ViewHolder public ViewHolder
onCreateViewHolder(ViewGroup parent, int viewType) { View v =
[Link]([Link]()) .inflate([Link].item_layout, parent, false);
return new ViewHolder(v); } @Override // Bind data to ViewHolder public void
onBindViewHolder(ViewHolder holder, int position) {
[Link]([Link](position)); } @Override public int getItemCount() { return
[Link](); } }
Setting up RecyclerView in Activity:
RecyclerView rv = findViewById([Link]); [Link](new
LinearLayoutManager(this)); MyAdapter adapter = new MyAdapter(dataList);
Wireless PSI / TO Exam Prep | Android Application Development Page 18
[Link](adapter);
✎ EXAM TIP: RecyclerView = modern ListView. ViewHolder = caches view references (performance).
onCreateViewHolder = inflate layout. onBindViewHolder = bind data. LayoutManager = arranges items!
Wireless PSI / TO Exam Prep | Android Application Development Page 19
Chapter 7
Working with Database — SQLite
■ 7.1 SQLite in Android
SQLite is a lightweight, embedded relational database built into Android. No separate server needed — database
stored as a single file in the app's private storage.
SQLite Feature Details
Type Embedded relational database — no server process needed
Storage Location /data/data/[Link]/databases/
File Format Single .db file — entire database in one file
SQL Support Standard SQL — CREATE, INSERT, SELECT, UPDATE, DELETE
Android Class SQLiteOpenHelper — helps create and version databases
Transactions Supports ACID transactions — begin/commit/rollback
Max DB Size ~140 TB theoretical — practical limit based on device storage
Modern Alternative Room Database (Jetpack) — annotation-based ORM over SQLite
■ 7.2 SQLiteOpenHelper
SQLiteOpenHelper is the Android class that manages database creation and version management. You extend it
to create your own database helper.
Method When Called What to Do
onCreate(SQLiteDatabase When database is
Execute CREATE TABLE SQL statements
db) created for FIRST time
When
onUpgrade(db,
DATABASE_VERSION Migrate data — ALTER TABLE or DROP + recreate
oldVersion, newVersion)
is incremented
Called to get writable DB
getWritableDatabase() Returns SQLiteDatabase for INSERT/UPDATE/DELETE
instance
Called to get readable
getReadableDatabase() Returns SQLiteDatabase for SELECT queries
DB instance
■ 7.3 Complete SQLite CRUD Example
Step 1 — Create DatabaseHelper class:
public class DatabaseHelper extends SQLiteOpenHelper { private static final String DB_NAME =
"StudentDB"; private static final int DB_VERSION = 1; private static final String TABLE =
"students"; public DatabaseHelper(Context context) { super(context, DB_NAME, null,
DB_VERSION); } @Override public void onCreate(SQLiteDatabase db) { String CREATE_TABLE =
Wireless PSI / TO Exam Prep | Android Application Development Page 20
"CREATE TABLE " + TABLE + " (" + "id INTEGER PRIMARY KEY AUTOINCREMENT, " + "name TEXT, " +
"age INTEGER, " + "email TEXT)"; [Link](CREATE_TABLE); } @Override public void
onUpgrade(SQLiteDatabase db, int oldV, int newV) { [Link]("DROP TABLE IF EXISTS " +
TABLE); onCreate(db); }
Step 2 — INSERT (Create):
// INSERT record public long insertStudent(String name, int age, String email) {
SQLiteDatabase db = [Link](); ContentValues values = new ContentValues();
[Link]("name", name); [Link]("age", age); [Link]("email", email); long id =
[Link](TABLE, null, values); [Link](); return id; // Returns row ID, -1 if error }
Step 3 — SELECT (Read):
// READ all records public List<String> getAllStudents() { List<String> list = new
ArrayList<>(); SQLiteDatabase db = [Link](); Cursor cursor =
[Link]("SELECT * FROM " + TABLE, null); if ([Link]()) { do { int id =
[Link](0); String name = [Link](1); int age = [Link](2); [Link](id
+ ": " + name + " (Age: " + age + ")"); } while ([Link]()); } [Link]();
[Link](); return list; }
Step 4 — UPDATE:
// UPDATE record public int updateStudent(int id, String newName, int newAge) {
SQLiteDatabase db = [Link](); ContentValues values = new ContentValues();
[Link]("name", newName); [Link]("age", newAge); int rows = [Link](TABLE, values,
"id=?", new String[]{[Link](id)}); [Link](); return rows; // Returns number of rows
affected }
Step 5 — DELETE:
// DELETE record public void deleteStudent(int id) { SQLiteDatabase db =
[Link](); [Link](TABLE, "id=?", new String[]{[Link](id)});
[Link](); } } // End of DatabaseHelper class
Step 6 — Using DatabaseHelper in Activity:
DatabaseHelper dbHelper = new DatabaseHelper(this); // INSERT: long id =
[Link]("Rahul", 21, "rahul@[Link]"); [Link](this, "Inserted ID: "
+ id, Toast.LENGTH_SHORT).show(); // READ and display in ListView: List<String> students =
[Link](); ArrayAdapter<String> adapter = new ArrayAdapter<>( this,
[Link].simple_list_item_1, students); [Link](adapter); // UPDATE:
[Link](1, "Rahul Kumar", 22); // DELETE: [Link](1);
✎ EXAM TIP: SQLiteOpenHelper: onCreate=first time DB created, onUpgrade=version changed.
ContentValues=key-value pairs for INSERT/UPDATE. Cursor=result of SELECT query. Always close
cursor and db!
■ 7.4 Cursor Methods
Cursor Method Purpose
moveToFirst() Move to first row — returns false if no rows
moveToNext() Move to next row — returns false if at last row
moveToPosition(int pos) Move to specific row by index
Wireless PSI / TO Exam Prep | Android Application Development Page 21
Cursor Method Purpose
getCount() Return total number of rows in cursor
getInt(int columnIndex) Get integer value from column at given index
getString(int columnIndex) Get string value from column at given index
getFloat(int columnIndex) Get float value from column at given index
getColumnIndex(String name) Get column index by column name
close() MUST close cursor after use to prevent memory leak
isAfterLast() Check if past last row
■ 7.5 Room Database — Introduction
Room is Google's recommended database library — an abstraction layer over SQLite. Part of Android Jetpack.
Room Component Purpose Annotation
Entity Java class representing a database table @Entity, @PrimaryKey, @ColumnInfo
DAO (Data Access Interface with database operations
@Dao, @Insert, @Update, @Delete, @Query
Object) (queries)
Abstract class — database holder and
Database @Database(entities, version)
main access point
Optional — mediates between DAO and
Repository No annotation — design pattern
ViewModel
✎ EXAM TIP: Room = modern SQLite wrapper = annotation-based. @Entity = table, @Dao = queries,
@Database = db holder. Room validates SQL at compile time — catches errors early. Preferred over raw
SQLite!
Wireless PSI / TO Exam Prep | Android Application Development Page 22
✍ QUICK REVISION CHEATSHEET
All key facts in one place
Concept / Parameter Key Fact
Android developer Google LLC (originally Android Inc., acquired 2005)
Android first release September 23, 2008 (Android 1.0)
Android based on Linux Kernel
Android language Java (primary), Kotlin (official since 2017), C/C++ (NDK)
Official IDE Android Studio (replaced Eclipse + ADT in 2013)
App file format .apk (Android Package) or .aab (Android App Bundle)
App store Google Play Store
Linux Kernel → HAL → Native Libraries + ART → Java API Framework
Android architecture layers (5)
→ System Apps
Dalvik VM Old Android runtime — JIT compilation — replaced in Android 5.0
Android Runtime — AOT compilation — faster, better battery — since
ART
Android 5.0
ART vs Dalvik ART = AOT (install time compile). Dalvik = JIT (runtime compile)
.dex file Dalvik Executable — bytecode format for both Dalvik and ART
Android 5.0 Lollipop ART replaces Dalvik, Material Design introduced
Android 6.0 Marshmallow Runtime permissions introduced
Android 8.0 Oreo Notification channels, Picture-in-Picture
Activity Single screen with UI — extends Activity or AppCompatActivity
onCreate→onStart→onResume→onPause→onStop→onRestart→onDe
Activity lifecycle order
stroy
onCreate() purpose Initialize UI, setContentView(), find views, set listeners
onResume() Activity in foreground — user can interact — RUNNING state
onPause() Activity partially hidden — save data, release camera
Explicit Intent Directly specify target class — Intent(this, [Link])
Implicit Intent Specify action — system finds app — ACTION_VIEW, ACTION_SEND
putExtra() / getStringExtra() Pass data between activities via Intent
[Link] Declares ALL activities, permissions, features — required
MAIN + LAUNCHER intent-filter that marks app entry point activity
uses-permission Declares permissions like INTERNET, CAMERA, READ_CONTACTS
ConstraintLayout Best performance layout — default for new projects
LinearLayout Arranges children in row or column — uses weight attribute
Wireless PSI / TO Exam Prep | Android Application Development Page 23
Concept / Parameter Key Fact
FrameLayout Stacks views — used for fragment containers
Toast.LENGTH_SHORT 2 seconds — Toast.LENGTH_LONG = 3.5 seconds
[Link]().show() MUST call .show() — forgot show() = no toast displayed
Options Menu Toolbar/ActionBar menu — onCreateOptionsMenu() + inflate XML
Long-press menu — registerForContextMenu() +
Context Menu
onCreateContextMenu()
[Link] setTitle, setMessage, setPositiveButton, setNegativeButton, show()
Adapter purpose Bridge between data source and ListView/RecyclerView
ArrayAdapter Simplest adapter — array/list data — built-in layouts
BaseAdapter Custom adapter — override getCount, getItem, getItemId, getView
Modern adapter — onCreateViewHolder, onBindViewHolder,
[Link]
getItemCount
ViewHolder pattern Cache view references — avoid repeated findViewById() calls
Controls RecyclerView layout: LinearLayoutManager,
LayoutManager
GridLayoutManager
SQLite location /data/data/[Link]/databases/
SQLiteOpenHelper Helper class — extends to create DB — onCreate + onUpgrade
onCreate(db) Called FIRST time DB created — execute CREATE TABLE SQL
onUpgrade(db,old,new) Called when DB_VERSION increases — migrate data
ContentValues Key-value pairs for INSERT and UPDATE operations
[Link]() INSERT row — returns row ID, -1 if error
[Link]() Execute SELECT SQL — returns Cursor
[Link]() UPDATE rows — returns number of rows affected
[Link]() DELETE rows from table
[Link]() Move to first row — false if no rows
[Link]() Iterate through results row by row
[Link]() MUST close cursor after use — memory leak if not closed
Room @Entity Annotates class as database table
Room @Dao Annotates interface with DB operations (@Query, @Insert, @Delete)
Room @Database Annotates abstract class — database holder
Fragment Reusable UI portion within Activity — has own lifecycle
res/layout/ XML layout files for activities and fragments
res/values/ [Link], [Link], [Link] — resource values
Auto-generated class — references to all resources ([Link],
R class
[Link])
Wireless PSI / TO Exam Prep | Android Application Development Page 24
■ TOP 12 EXAM TIPS
High-probability points — memorize before exam day
Android = Google + Linux-based + Open Source. First release = Sept 23, 2008. Official IDE = Android
Tip 1
Studio (2013). Language = Java/Kotlin. App format = .apk/.aab!
5 Architecture layers: Linux Kernel → HAL → ART+Native Libraries → Java API Framework → System
Tip 2
Apps. Linux kernel = bottom. System Apps = top!
ART replaced Dalvik in Android 5.0 Lollipop. ART = AOT (ahead-of-time) compile at install. Dalvik = JIT
Tip 3
(just-in-time) at runtime. ART = faster + better battery!
Activity lifecycle: onCreate→onStart→onResume(running)→onPause→onStop→onDestroy. onCreate
Tip 4
= setup UI. onResume = user interacts. onPause = save data!
Explicit Intent = specify class directly (within app). Implicit Intent = specify action (system picks app).
Tip 5
putExtra/getStringExtra = pass data between activities!
[Link] = declares ALL activities + permissions. MAIN+LAUNCHER = app entry point.
Tip 6
uses-permission = INTERNET, CAMERA, etc. Missing declaration = app crashes!
ConstraintLayout = best performance = default. LinearLayout = simple row/column. FrameLayout =
Tip 7
fragment container. RelativeLayout = relative positioning!
Toast: makeText(context, message, duration).show(). LENGTH_SHORT=2s. LENGTH_LONG=3.5s.
Tip 8
MUST call show() or toast wont appear. Toast cannot be clicked!
Options Menu = toolbar (onCreateOptionsMenu). Context Menu = long-press
Tip 9
(registerForContextMenu). [Link]: setPositiveButton=Yes, setNegativeButton=No!
Adapter = bridge between data and ListView. ArrayAdapter = simple. BaseAdapter = custom.
Tip 10
[Link] = modern. ViewHolder = cache view refs for performance!
SQLiteOpenHelper: onCreate=first DB creation (CREATE TABLE). onUpgrade=version change.
Tip 11
ContentValues=INSERT/UPDATE data. Cursor=SELECT results. ALWAYS close cursor!
Room = modern SQLite: @Entity=table, @Dao=queries, @Database=holder. Fragment = reusable UI
Tip 12
in Activity. [Link] = resource reference. res/layout = XML layouts!
All the best for your Wireless PSI / Technical Operator Exam! Prepare smart, revise daily, practice
MCQs regularly. ■
Wireless PSI / TO Exam Prep | Android Application Development Page 25