Android Viva Preparation Notes
1. Basic Terms in Android System
● Android OS
○ Open‑source, Linux‑based mobile operating system by Google.
○ Supports multitasking, rich UI, optimized power and memory use.
● APK (Android Package)
○ .apk file format used to distribute and install Android apps.
○ Contains compiled code (classes.dex), resources, manifest, certificates.
● Activity
○ A single screen with a UI.
○ Lifecycle methods manage creation, display, pause, stop, and destruction.
● Service
○ Background component running long‑running operations (e.g., music
playback, data sync) without a UI.
○ Lifecycle: onCreate(), onStartCommand(), onDestroy().
● Broadcast Receiver
○ Listens for system- or app‑wide broadcast Intents (e.g.,
BOOT_COMPLETED, SMS_RECEIVED).
○ Implement onReceive(Context, Intent).
● Content Provider
○ Exposes app data via a standardized interface—URI-based CRUD operations
on SQLite or other storage.
○ Key methods: query(), insert(), update(), delete().
● Intent
○ Messaging object for component communication.
○ Explicit Intents target a specific component; Implicit Intents let the system find
a suitable component.
● Fragment
○ Reusable UI component hosted by an Activity.
○ Can be added/removed dynamically; supports its own lifecycle callbacks
(e.g., onCreateView()).
● AndroidManifest.xml
○ Declares app components (Activities, Services, etc.), permissions
(<uses-permission>), minimum SDK, features.
● Gradle
○ Build automation system that handles project structure, dependencies, build
variants, and APK packaging.
2. Android Architecture
1. Linux Kernel (Bottom Layer)
○ Core OS services: memory, process, driver frameworks for camera, Wi‑Fi,
audio.
2. Hardware Abstraction Layer (HAL)
○ C/C++ libraries exposing standardized APIs to upper layers for each
hardware module.
3. Android Runtime & Libraries
○ ART (Android Runtime): Ahead‑of‑time (AOT) compilation of .dex to
machine code, improved performance over Dalvik.
○ Core Java Libraries: Collections, I/O, utilities.
○ C/C++ Native Libraries: SQLite, OpenGL ES, WebKit, SSL, Media codecs.
4. Application Framework
○ Managers for Activities, Resources, Notifications, Telephony, Window,
Location, Package.
○ Provides high‑level building blocks (Views, Adapters, Services).
5. Applications (Top Layer)
○ System apps (Phone, Settings) and user‑installed apps, each sandboxed with
a unique Linux user ID.
3. Tools & Software Required
● Android Studio
○ Official IDE with code editor (Java/Kotlin), visual layout editor, debugger,
profiler.
● Java Development Kit (JDK)
○ Provides javac, java for compiling and running code; usually bundled with
Studio.
● Android SDK
○ Platform APIs, build tools, system images for emulators.
● AVD Manager & Emulator
○ Create and run Android Virtual Devices with specific configurations (API level,
RAM, screen size).
● Gradle
○ Manages dependencies (implementation, api), build flavors, signing
configs.
● Version Control
○ Git for source‑control, collaboration, and code history.
● Additional Libraries (optional)
○ Jetpack (Lifecycle, ViewModel, Room, Navigation), Firebase, Retrofit, Glide,
etc.
4. Core Concepts & Definitions
Android Development Tool (ADT)
● Eclipse plugin (now deprecated) that provided Android project templates, layout
editors, and DDMS integration.
Android Virtual Device (AVD)
● Configuration profile for the emulator. Defines screen dimensions, API level,
hardware features.
Emulator
● Software simulation of an Android device. Can emulate GPS, battery, GSM,
calls/SMS, network conditions.
Dalvik Virtual Machine (DVM)
● Original bytecode interpreter up to Android 4.4. Optimized for low memory; executed
.dex files in register‑based VM.
Java Virtual Machine (JVM)
● Standard Java runtime environment. Stack‑based, executes .class files; used on
desktops/servers.
DVM vs. JVM
Feature DVM JVM
Bytecode Format .dex .class
Architecture Register‑based VM Stack‑based VM
Optimization Low‑memory, mobile devices General‑purpose, high
performance
Multithreading Process‑based STUB Thread‑based model
threads
Target Platform Android devices Desktop/server Java apps
5. Layouts & UI Design
Fundamental UI Principles
● Consistency: Uniform look and behavior across screens.
● Feedback: Immediate visual response to user actions.
● Clarity: Simple, legible content hierarchy.
● Accessibility: Support for screen readers, high‑contrast text, touch targets.
Directory Structure
MyApp/
├── manifests/ # AndroidManifest.xml
├── java/ # Source code (Activities, Fragments, Adapters)
└── res/
├── layout/ # XML layout files
├── drawable/ # Images, shapes, selectors
├── values/ # Strings, dimensions, styles
└── mipmap/ # App icons
Common Layouts
1. LinearLayout
○ android:orientation="vertical|horizontal", layout_weight for
proportional sizing.
XML Example:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView …/>
<Button …/>
</LinearLayout>
○
2. RelativeLayout
○ Position children via layout_alignParentTop,
layout_below="@id/view1".
3. FrameLayout
○ Simple container stacking children; typically used for fragments.
4. TableLayout
○ Uses <TableRow>; each child in a row becomes a column cell. Suited for
form‑like UIs.
5. AbsoluteLayout (deprecated)
○ Fixed x,y coordinates; not responsive.
6. ConstraintLayout
○ Modern, flexible; position views with constraints
(app:layout_constraintStart_toEndOf).
○ Reduces nested layouts and improves performance.
6. Views & Widgets
Widget Purpose Key Attributes
TextView Display read‑only text android:text, android:textSize,
android:textColor
EditText Accept user text input android:hint,
android:inputType="textEmailAddre
ss"
Button Trigger an action on click android:onClick="handleClick"
ImageButton Clickable image android:src="@drawable/icon"
ToggleButto Two‑state ON/OFF switch android:checked, android:textOn,
n android:textOff
RadioButton Single selection Placed inside a RadioGroup
RadioGroup Container enforcing single android:orientation
RadioButton selection
CheckBox Multiple selections android:checked
allowed
ProgressBar Show operation progress style="?android:attr/progressBarS
tyleHorizontal"
ListView Vertical, scrollable list of android:divider, uses ArrayAdapter
homogeneous items
GridView Scrollable grid of items android:numColumns="auto_fit",
columnWidth
ImageView Display images android:src, android:scaleType
ScrollView Enable vertical scrolling Wraps a single child layout
for large content
Custom Brief popup messages Inflate custom XML, then
Toast with custom layout Toast.setView(view)
TimePicker Select hour/minute android:timePickerMode="spinner"
DatePicker Select day/month/year android:calendarViewShown="true"
7. Advanced Topics
Activity Lifecycle
onCreate() → onStart() → onResume()
↓ ↑
onPause() → onStop() → onDestroy()
↑
onRestart()
● onCreate(): Initialize UI, restore state.
● onResume(): Acquire resources (camera, sensors).
● onPause(): Commit unsaved changes, release resources.
● onStop(): Clean up heavy resources.
● onDestroy(): Final cleanup before termination.
Bluetooth
● API Steps:
1. Check BluetoothAdapter availability and enable it.
2. Discover devices with startDiscovery().
3. Pair via createBond(), connect with BluetoothSocket.
4. Exchange data over Input/Output streams.
SQLite Database
● Embedded, file‑based RDBMS.
Use SQLiteOpenHelper subclass:
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE notes(id INTEGER PRIMARY KEY, text TEXT);");
}
●
● CRUD via db.insert(), db.query(), db.update(), db.delete().
SMS Telephony
Permissions:
<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
●
Send SMS:
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(number, null, message, null, null);
●
● Receive SMS: Implement BroadcastReceiver for
android.provider.Telephony.SMS_RECEIVED.
Android Security Model
● Sandboxing: Each app runs as its own Linux user.
● Permissions: Declared in manifest; dangerous permissions require runtime grant.
● App Signing: Ensures authenticity and allows updates.
● Google Play Protect: Scans for malware.
● Encrypted File Storage: Supports file‑level encryption (Android 7+).
Application Deployment
1. Debug Build: assembleDebug via Gradle; signed with debug key.
2. Release Build:
○ Generate private key (keystore).
○ Configure signingConfigs in Gradle.
○ Run assembleRelease.
3. Testing: Use emulators, real devices; perform instrumentation (Espresso) and unit
tests.
4. Publishing:
○ Create Play Store listing (description, screenshots, icons).
○ Upload signed APK or App Bundle (.aab).
○ Set rollout percentage, review, then publish.