0% found this document useful (0 votes)
19 views65 pages

Mobile Notes

Mobile Application notes

Uploaded by

Saail Abbas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views65 pages

Mobile Notes

Mobile Application notes

Uploaded by

Saail Abbas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 65

Lecture 1

1 Why Mobile Development Matters

Key Facts

• 10x more phones sold than PCs.

• More people use the internet on phones than on computers.

• Phones = small, portable computers with touch, sensors, camera, GPS, etc.

• People carry phones everywhere. Most sleep with them. Apps are personal.

What This Means for You as a Developer:

• You must design for small screen and touch-based input.

• Be smart about battery, memory, and performance.

• Your apps must work in different environments (light, dark, inside,


outside).

1.1 Special Features of Mobile Devices

Feature Explanation

Touch Input Apps take input via tap, swipe, etc.

Sensors Detect motion, light, direction (gyroscope, accelerometer)


Connectivity WiFi, Mobile Data, Bluetooth

Personal Use One user per device — apps can be personalized

Limited Resources Less RAM/CPU compared to PC — must optimize

Context of Use Use changes — at home, outside, walking, etc.

Short Usage Time Users don’t stay long — app must be quick & clear

1.2 Why Traditional Web Pages Don’t Work Well on Phones

• Small buttons = hard to tap.

• Typing is slow.

• Big content = doesn’t fit on screen.

• Solution: Make mobile-friendly UIs with fewer items per screen and bigger
buttons.

1.3 Mobile Users = Multitaskers

• They use your app for 10 seconds, then get a call or notification.

• Your app should save state and recover quickly.

• Don't make users wait or they will uninstall the app.


1.4 Mobile Apps Need to Be:

• Lightweight

• Fast

• Simple

• Reliable even when offline or with weak internet

• Safe (privacy + security)

2 Types of Mobile Apps

Type How It Works Tools Best Use

Native Built only for one Android Studio, Best performance, deep
OS (e.g. Android) Java/Kotlin hardware access

Web App Runs in browser HTML, CSS, JS Cheap, universal, but


weaker performance

Cross- One code for both Flutter, React Saves time, good for
Platform iOS & Android Native startups

Hybrid Web app inside a Ionic, Cordova Fast dev, less hardware
native wrapper access
2.1 Why You’re Studying Native Apps:

• Deepest understanding of Android OS

• Best access to camera, GPS, sensors

• Better performance and security

• More jobs still demand native Android skills

3 Introduction to Android

• Android is an operating system based on Linux, made for smartphones and


tablets.

• Developed by Google + Open Handset Alliance.

• First version: 2008

Main Features:

• Open-source = free to use and modify

• Can run on many devices (Samsung, Vivo, etc.)

• Huge developer community

Android Development – Tools

Tool Purpose

Android Studio Main IDE for writing apps


Java/Kotlin Languages used to write Android code

SDK Tools to build and run your apps

Emulator Fake phone inside your computer

JDK Java tools needed to compile apps

Version Control Git tracks your code changes (important for group projects)

4 Exam Questions

“Why choose native over hybrid?”

Native apps are built specifically for one platform using official tools like Android
Studio and Java/Kotlin. They give high performance, full access to hardware (like
GPS, camera), and better security. In contrast, hybrid apps are faster to build but
may have lower performance and limited device access.

“Explain different mobile app types with examples”

Mobile apps can be native, web, cross-platform, or hybrid. Native apps like TikTok
(Android) use Java/Kotlin and work only on one OS. Web apps like Facebook (in a
browser) use HTML/CSS/JS and work in browsers. Cross-platform apps like
Airbnb use Flutter or React Native to work on both Android and iOS. Hybrid apps
like Twitter are web apps wrapped in a native shell using tools like Ionic.
Key Revision Flash Points

• Android = Linux-based, open-source mobile OS

• Native app = built for one platform → fast + full hardware access

• Web app = runs in browser → cheap but limited

• Cross-platform = one code for both Android/iOS

• Hybrid = web app inside native shell

• Android Studio = official IDE

• Java/Kotlin = main languages

• Phones = low power, short attention, multitasking users


Lecture 2
5 The First Android App

Goal: Understand how to create your first Android app and run it.

Basic Steps:

1. Open Android Studio

2. Create New Project

o Choose “Empty Activity”

o Give your app a name (e.g., HelloWorld)

3. Configure Project (Set:

o App name

o Package name (like com.yourname.helloworld)

o Language (Java/Kotlin)

o Minimum SDK (Android version to support)

4. Finish & Wait – Android Studio builds your project.


5.1 What Files Are Created?

File Purpose

MainActivity.java Your app’s starting logic (code)

activity_main.xml Layout for the UI (what the screen looks like)

AndroidManifest.xml Settings of app (permissions, main activity, etc.)

5.2 Running the App

You have 2 choices:

• Use AVD (Android Virtual Device) — built-in emulator

• Use a real phone (USB Debugging ON)

In Studio, click the green triangle to run.


Choose emulator/real phone → App installs → You’ll see Hello World on screen.

Tour of Android Studio

Part Purpose

Toolbar Run app, open SDK, tools

Project Window View all app files

Editor Window Write code here


Design Tab Drag-drop UI buttons

AVD Manager Create/run emulators

Logcat Debug output — see errors, logs

Use Design tab for drag-drop, Text tab to edit XML directly.
6 Android Architecture

LAYER 1: Linux Kernel (Bottom Layer)

• Written in C

• Manages hardware: battery, screen, camera, memory

• Does low-level tasks like process scheduling, networking

LAYER 2: Libraries + Runtime

• Libraries like:

o SQLite (database)

o WebKit (browser)

o SSL (security)

• Android Runtime (ART) or older Dalvik VM runs your app’s code

LAYER 3: Application Framework

• Tools to create apps

• Gives access to:

o Activities

o Services

o Notifications

o Content providers
o Window manager

LAYER 4: Your Apps (Top Layer)

• This is where you write code!

• App sits on top and uses all lower layers

7 ANDROID BUILD PROCESS (What Happens


When You “Run” the App)

Steps:

1. You write Java/Kotlin code

2. It is converted to DEX (Dalvik Executable)

3. All files + resources → packed into APK

4. APK is signed using debug or release key

5. Final APK is installed on device/emulator

Gradle handles this whole build process.


7.1 Custom Build Concepts (Used in Industry Projects)

Term Meaning

Build Type Debug vs Release

Product Flavor Free vs Paid versions of your app

Build Variant Combination of Build Type + Flavor

Manifest Allows different settings (like name, min SDK) for each
Merge variant

Dependencies Other libraries your app uses (like Glide, Firebase)

Signing Required to publish app on Play Store


8 ANDROID APP COMPONENTS — The 4 Pillars of
Every App

8.1 Activity

One screen of the app. Controls what user sees and interacts with.

Example:

• MainActivity: Home screen

• SettingsActivity: Settings screen

Each Activity has:

• Its own layout file (XML)

• Must be declared in AndroidManifest.xml


8.2 Service

Background process — no UI. Keeps running even when activity is not open.

Examples:

• Music player

• Download manager

Code:

8.3 Broadcast Receiver

Listens for system events (e.g., battery low, SMS received)

Examples:

• Trigger alarm when device boots

• Show message when internet disconnected

Code:
8.4 Content Provider

Shares structured data between apps

Examples:

• Contacts

• Calendar

• Files

Code:

9 INTENTS — How Components Talk

Intent = message used to start an Activity, Service, or Broadcast


Example: Start another activity

Intents can:

• Start activities (startActivity)

• Start services (startService)

• Send messages (sendBroadcast)

10 XMPP + Notification Manager

• XMPP = messaging protocol (used in real-time chat apps like WhatsApp)

• Notification Manager = shows background messages/alerts in status bar

11 Hardware Layers You Must Understand

Component Role

Sensors Motion, light, proximity

CPU/GPU/DSP Brain of device – controls speed, display, sound


Flash/RAM Storage & memory

Transceivers Handle WiFi, Bluetooth, NFC

Linux Kernel Manages power, camera, display, etc.

12 Emulator: Use with Caution

A virtual phone on your PC. Good for early testing, but…

Emulator Limitations:

• No real phone calls

• No camera input

• No Bluetooth

• No battery sensor

• SLOW!

Best to test final app on a real Android device.

Exam Questions:
“List and explain core Android app components”
Android has four main components: Activities (screens), Services (background
tasks), Broadcast Receivers (event listeners), and Content Providers (data sharing).
These components allow an Android app to run, interact with the system, and
respond to user and system events.

“Describe the Android Architecture”

Android architecture has four layers. The bottom layer is the Linux Kernel
(hardware access). The second is Libraries and Runtime (where your code runs).
The third is Application Framework (gives app tools like Activity Manager). The
top layer is Applications, where user apps live.
LECTURE 3

13 Android UI Tour

➤ Home Screen

• This is the first screen you see after unlocking your phone.

• It has:

o Favorites tray: Quick access apps (like Phone, Messaging, Browser).

o Widgets: Small app windows (like weather, clock).

➤ All Apps Screen

• Accessed by tapping the All Apps Button (grid icon).

• Shows all installed apps.

• You can swipe through pages and customize layout.

➤ Recent Apps Screen

• Accessed by touching the Recent Apps Button (square/3-line icon).

• Shows recently opened apps.

• You can switch between apps quickly by tapping any app.

➤ Status Bar and Notification Screen


• Status Bar: Shows tiny icons at the top for:

o Time

o Battery

o Network signal

o Bluetooth, etc.

• Notification Panel (pull down from the top):

o Shows notifications from apps like:

▪ Wi-Fi Connected

▪ New Email

▪ Music Playing

▪ USB connected

o You can clear or respond to notifications from here.

13.1 Android Apps: Big Picture

➤ Key Point: Android separates UI and Code

• UI Design is done using XML.

• App Logic/Behavior is done using Java/Kotlin.

Why?

• You can change app design without touching the Java code.
• Faster updates and cleaner organization.

14 How Android App is Compiled

• Android Studio takes your:

o Java Code

o XML Layouts

o Resources (images, strings)

• And compiles them into one single file:

o APK file (Example: myapp.apk)

o APK = Like a Windows .exe installer

• APK installation: You either download from Play Store or manually install
.apk file.

15 First Android App: Hello World

➤ 3 Important Files in Every Simple Android App

File Purpose

activity_main.xml Defines how your app looks (UI layout)

MainActivity.java Defines how your app behaves (logic on button click


etc.)
AndroidManifest.xml Defines app structure (entry point, permissions, etc.)

16 Execution Order (How Android App Runs)

1. AndroidManifest.xml
→ App starts reading the file. → Finds which Activity is marked as
LAUNCHER (the starting screen).

2. MainActivity.java
→ Code inside onCreate() runs. → It links to the layout file.

3. activity_main.xml
→ Layout file is loaded and displayed.

16.1 Inside Each File (Simple View)

16.1.1 ➤ MainActivity.java

• Imports necessary Android classes.

• Inherits from Android's Activity class.

• Overrides onCreate() method.

• Sets layout using setContentView(R.layout.activity_main);

Example:
16.1.2 ➤ activity_main.xml

• Layout of the screen.

• Written in XML.

• Adds Views like:

o TextView (for text)

o Button (for click)

o ImageView (for pictures)

Example:
16.1.3 ➤ AndroidManifest.xml

• Lists all screens (Activities).

• Defines permissions (e.g., internet access).

• Tells which Activity should start first (Launcher).

17 Designing UI with XML

• Views = UI elements (TextView, Button, ImageView).

• ViewGroups = Layout managers (LinearLayout, RelativeLayout,


ConstraintLayout).

Steps:

1. Declare a Layout (e.g., LinearLayout).

2. Add Widgets inside the layout.

3. Set properties (width, height, gravity, margins).


18 Important Folders in Android Project

Folder Purpose

res/layout/ XML files for screen layouts

res/drawable/ Images (JPG, PNG)

res/values/ Strings, dimensions, styles

res/menu/ Menu files

res/raw/ Other files like audio, videos

19 Strings in Android

• Instead of hard-coding text inside XML, save them in strings.xml for easy
editing.

Example:
Advantage: Change in one place reflects everywhere!

20 Styling Android Apps

• Styles are like CSS for Android.

• Define color, size, font for multiple views together.

Example:

21 Adding Pictures in Android

• Supported formats: PNG, JPEG, GIF


• Stored in res/drawable-mdpi, drawable-hdpi, etc.

• Android automatically selects the best resolution based on device screen.

You reference image like:

22 Screen Dimensions

Term Meaning

Screen Size Diagonal size (e.g., 5.5 inches)

Resolution Total number of pixels (e.g., 1080x2400)

Density (DPI) Pixels per inch (e.g., 320 dpi = xhdpi)

DPI Types:

• ldpi (low)

• mdpi (medium)

• hdpi (high)

• xhdpi (extra high)

• xxhdpi (extra extra high)

• xxxhdpi (highest)
LECTURE 4
23 Android UI Design using XML

➤ Recall the Three Main Files:

File Name Purpose

activity_main.xml Defines how the screen looks (layout, design)

MainActivity.java Defines how the app behaves (what happens on click,


etc.)

AndroidManifest.xml Lists all components/screens of app and marks starting


screen (Launcher)

23.1 Widgets

Widgets = UI components that the user can see and interact with.

Examples:

• TextView (shows text)

• EditText (for user to type input)

• Button (for clicking)


Design Approaches:

• Drag and Drop in Android Studio Design View

• Edit XML Directly in Text View

Dragging widgets auto-generates XML code!

24 Common Android Widgets

24.1 TextView

• Shows text to the user.

• Not interactive (user cannot click or edit it).

Important TextView Properties:

Property Use

android:text The text shown

android:textSize Size of text

android:textColor Color of text

android:textStyle normal, bold, italic

android:background Background color


android:visibility Show or hide the TextView

Text Size Units:

• px (pixels): BAD. Looks different on different screens.

• dp (density pixels): Better. Independent of device density.

• sp (scaled pixels): BEST for text. Respects user's font settings.

Always prefer sp for textSize.

24.1.1 ➤ Widget ID (android:id)

• Every widget should have a unique ID.

• ID is needed to find and control the widget from Java code.

ID Usage:

Action Syntax

First time create ID @+id/widget_name

Refer later @id/widget_name


Example:
24.2 Button

• A clickable widget.

• Can have text, icon, or both.

• Subclass of TextView, so it shares many properties.

How Button Click Works:

1. In XML: Set android:onClick="methodName"

2. In Java: Create a method with that name.

Example:
24.3 ImageView and ImageButton

• ImageView: Just displays an image.

• ImageButton: An image that acts like a button (clickable).

Set Image Source:

Image Scaling (scaleType options):

ScaleType What It Does

center Places image in center without resizing

centerCrop Scales image and crops excess

fitXY Stretches image to fit (may distort)

24.4 EditText

• Allows user to input text (name, email, password, etc.).

Setting Input Type:


InputType Usage

text Normal text

number Only numbers

phone Phone number

password Hidden text for passwords

Example:

24.5 Spinner

• Drop-down list.

• User selects one option from several choices.

Example:

• Selecting "Male", "Female", "Other" in a form.


24.6 Checkbox

• Has two states: checked or unchecked.

• Clicking toggles the state.

• Subclass of TextView, so it also supports textColor, etc.

Example:

24.7 Pickers (DatePicker and TimePicker)

• Used to select a date or select a time.

• Shown in a small popup dialog.

Example:

• Selecting date of birth, or setting an alarm.

24.8 Indicators

Widget Use
ProgressBar Shows loading progress

RatingBar User gives rating (stars)

Chronometer Timer to count time (stopwatch)

DigitalClock Shows time digitally

AnalogClock Shows clock face

25 Special Important Notes from Lecture

26 ➤ Gravity vs Layout Gravity

• gravity → Align content inside a view.

• layout_gravity → Align the whole view inside parent layout.

Important:

• layout_gravity only works properly in LinearLayout or FrameLayout,


NOT RelativeLayout.

• wrap_content + layout_gravity = useless (no space to move).

• match_parent + layout_gravity = useless (already fills parent).


27 ✨ Extra Pro-Level Insights (Not in Slide, But
Important)

1. Best Practice for IDs:

o Use meaningful names like btnSubmit, txtUserName instead of


button1, textview1.

2. Why Use dp and sp instead of px?

o dp = Same size across all devices, regardless of screen density.

o sp = Same size + user accessibility settings respected.

3. Handling Clicks in Java (Best Way): Instead of android:onClick, you can


programmatically set click listeners for more control:

4. Avoid Hardcoding Strings: Always put your strings in strings.xml for easy
translation and maintenance.
5. Organizing Images: Put images with different resolutions (mdpi, hdpi,
xhdpi) to make apps look crisp on all devices.

28 FINAL QUICK SUMMARY (REVISION)

Topic Key Points

XML Layout Design screen using TextViews, Buttons, etc.

Widget ID @+id/xyz for first time, @id/xyz later

Button Click XML android:onClick OR Java Listener

ImageView Display images with android:src

TextView vs Display text vs Accept text


EditText

Input Types Number, Email, Password, etc.

Spinner Dropdown choices

ProgressBar Loading indicator

Gravity Align content inside

Layout Gravity Align view inside parent (LinearLayout/FrameLayout


only)
Lecture 5:
29 What is a Layout in Android?

A layout defines how your app's screen looks. It controls where and how UI
elements (buttons, text, images) appear.

You write layouts using XML (like HTML) in Android.

29.1 LinearLayout – Simple and Sequential

What It Does:

• Places elements one by one.

• You choose the direction: vertical (top to bottom) or horizontal (left to


right).

Key Attribute:

Example (Vertical):
Weight System – How Space Is Shared:

• android:layout_weight decides how much space each item takes.

• If no weight is given → the item takes only the size it needs.

• If weights are given, the remaining space is shared based on those weights.

Example:

The first two take 1 unit each.

• The last one takes 2 units → more space.

weightSum (Optional)

• Can be used to set total weight (not often needed unless fine-tuning).
29.2 RelativeLayout – Position-Based Layout

What It Does:

• You can place views in relation to:

o Other views (e.g., below a button)

o The parent (e.g., center of screen)

Useful Attributes:

Attribute Meaning

layout_below="@id/view" Place below a view

layout_alignParentTop="true" Align to top of screen

layout_centerInParent="true" Center in screen

layout_toRightOf="@id/view" To the right of a view

Example:
Use When:

• You want custom positions, not just vertical/horizontal flow.

29.3 ConstraintLayout – Powerful and Flexible

What It Does:

• Advanced layout that allows you to place items anywhere, but still clean and
optimized.

• Reduces need for nested layouts (which can slow apps down).

• Each item can be "anchored" to another item or to the screen sides.

How It Works:

Each view has:

• Side Handles – to set top, left, right, bottom positions

• Resize Handles – to change size


• Baseline Handle – to align text fields properly

Example:

• This button stretches full width of screen.

29.3.1 ConstraintLayout Features:

A. Chains

• Used to arrange multiple views together in a row or column.

• Unlike LinearLayout, chains allow more flexible control.

Types of Chains:

Type Behavior

Spread Evenly distributes views

Spread Inside Leaves gaps at start and end

Packed Views are close together in center


B. Match Constraints Mode

• Set width/height to 0dp → lets the constraint decide size.

• Use this for dynamic layouts.

C. Deleting Constraints

• Select constraint → it turns red → click to delete.

• You can also Delete All Constraints using the button in the UI.

29.4 Extending Layouts

A. include Tag

• If you have a layout you want to reuse in many places, define it once and
include it like this:

• Saves time, avoids repeating code.

29.5 Custom Views

30 What Are Custom Views?


• If default views (Button, TextView) don’t do what you want, you can create
your own component (like a fancy button or shape).

• You subclass View or existing classes.

31 Example: Circular ImageView

• You can build a Circular ImageView for profile pictures using libraries or
by drawing manually.

32 Steps to Use Custom View:

1. Add a library dependency in build.gradle

2. Use the custom tag in XML:

xml

CopyEdit

<com.example.CircularImageView

android:layout_width="100dp"

android:layout_height="100dp"/>

33 Bonus Tips

• Use ConstraintLayout for most modern apps — it’s better for performance.

• Use LinearLayout for simple forms (login, sign-up).


• Don’t over-nest layouts (e.g., LinearLayout inside RelativeLayout inside
another).

• Use "dp" for sizes, "sp" for text — always.

• Try to use wrap_content and match_parent smartly. wrap_content sizes to


content, match_parent fills the screen.
Lecture 6:

34 What is an Activity?

An Activity is a single screen in your Android app. Think of it as one page in a


mobile application.

Examples:

• Login screen → one activity.

• Home screen → another activity.

• Profile screen → yet another activity.

Each activity has its own lifecycle, which means Android manages it from creation
to destruction — just like a human life.

35 Android’s Process Model

When you open an app:

1. Android copies a template process called Zygote.

2. Zygote contains:

o The Java Virtual Machine

o Core Android framework classes (e.g. Activity, Button)


o Your app's code (from APK)

This helps Android start apps faster.

36 Activity Stack and Buttons (Back vs Home)

Button What It Does

Back Destroys current activity.

Home Hides app but keeps it alive in memory.

Stack Behavior:

• Last opened activity is on top.

• If memory is low, Android may destroy lower activities.

37 Activity Lifecycle: Full Breakdown

Android calls lifecycle methods automatically when the state of your activity
changes.

onCreate()

• Called when activity is first created.

• Used to:
o Load layout using setContentView()

o Find views like buttons using findViewById()

o Set listeners (e.g., what to do when a button is clicked)

onStart()

• Called just before activity becomes visible.

• Good for preparing UI.

onResume()

• Called when activity is fully visible and ready for user interaction.

• Resume animations, audio, etc.

onPause()
• Called when activity is partially hidden (e.g., a dialog shows or a phone call
comes in).

• Stop animations, sensors, video, GPS to save battery and CPU.

onStop()

• Called when activity is completely hidden.

• Save data, release resources.

onRestart()

• Called if user returns to the app after it was stopped.

onDestroy()

• Called when activity is about to be destroyed.

• Cleanup code goes here.

37.1 Full Lifecycle Flow:

onCreate() → onStart() → onResume()

User interacts...
→ onPause() → onStop() → onDestroy()

(OR → onRestart() → onStart() → onResume())

38 State Diagram Examples

38.1 Running State

• Activity is visible and in foreground.

• onCreate() → onStart() → onResume()

38.2 Paused State

• Activity is still visible but not active (e.g., pop-up appears).

• onPause() called.

38.3 Stopped State

• Completely hidden. No code running.

• onStop() called.

39 Saving App State (Very Important for Midterms)

When Android destroys and recreates activity (like after rotation), your variables
are lost unless you save them.
39.1 onSaveInstanceState(Bundle outState)

• Save data to a Bundle (a key-value dictionary).

• Called before onDestroy() during rotation.

39.2 Restore it in onCreate():

39.3 Rotation (Portrait ↔ Landscape)

• Rotation destroys the current activity and recreates it.


• To keep data (like form input or game progress), use onSaveInstanceState()
and onRestoreInstanceState().

40 Logging with Logcat

Used to print messages to Android Studio Logcat window for debugging.

Methods (ordered by importance):

Example:

";

Log.d(TAG, "onCreate called");

Tip: Add logs in all lifecycle methods to see when each is called.

41 Action Bar
• It shows at the top of your app.

• Can show title, menu items, or navigation buttons.

• Usually added in onCreate().

42 BONUS: Midterm Exam Hot Questions (Likely)

1. List and explain lifecycle methods.

2. What is the difference between Back and Home button?

3. When do you use onSaveInstanceState()?

4. Explain how to restore state after screen rotation.

5. Write code for logging activity lifecycle events.

6. Why should you stop sensors/audio in onPause()?

7. Difference between onStop() and onDestroy()?


SECTION A: Theory Questions

What are the major types of Mobile Applications? Explain with examples.

Answer:

• Native Apps: Built for a specific platform. Example: TikTok (Android).

• Web Apps: Accessed through a browser. Example: Facebook Web.

• Cross-platform Apps: One code for both Android and iOS. Example:
Flutter-based Airbnb app.

• Hybrid Apps: Web app inside a native shell. Example: Twitter Mobile App
(old versions).

Why are native apps preferred over hybrid apps?

Answer:

• Native apps offer better performance, deeper hardware access (camera,


GPS), and higher security.

• Hybrid apps are faster to build but lower performance and limited
hardware features.

What are the 4 major components of Android Apps? Briefly explain.


Answer:

• Activity: A single screen UI.

• Service: Runs tasks in the background.

• Broadcast Receiver: Listens for system-wide events.

• Content Provider: Shares app data between apps.

Explain the Android Architecture Layers.

Answer:

1. Linux Kernel – Access to hardware like memory, camera.

2. Libraries + Runtime – Code execution (SQLite, WebKit, ART).

3. Application Framework – Provides services (Activity Manager, Content


Providers).

4. Applications – User apps built by developers.

What happens inside onCreate() method?

Answer:

• Set layout using setContentView().

• Find and initialize UI widgets with findViewById().


• Set event listeners (like button clicks).

Differentiate between Back Button and Home Button behavior.

Answer:

• Back Button: Destroys the current activity and goes back to previous screen.

• Home Button: Minimizes the app, but keeps it in memory (paused/stopped).

Describe the full Activity Lifecycle with method names.

Answer:

text

CopyEdit

onCreate() → onStart() → onResume()

(onPause() → onStop()) → (onRestart() → onStart() → onResume())

→ onDestroy()

Each method handles a specific state like initialization, visibility, pause, stop, and
destruction.

What is onSaveInstanceState() used for?


Answer:

• Saves small important data (form entries, scores) before the activity is
destroyed (like during screen rotation).

• Data is saved into a Bundle.

What is an Intent? What are its types?

Answer:

• Intent = a message to do something (start screen, open link).

• Explicit Intent: Move within same app (Activity A → B).

• Implicit Intent: Request system to perform an action (open browser, send


SMS).

What is the use of <include> tag in layouts?

Answer:

• To reuse existing layouts inside another layout without copying code.

• Makes UI modular, clean, and easier to manage.

What is a ConstraintLayout? Why is it used?

Answer:
• Advanced layout that allows placing UI items anywhere with flexible
constraints.

• Reduces nested layouts, making apps faster and smoother.

Define Logcat. How is it helpful?

Answer:

• Logcat is a window in Android Studio that shows system messages, errors,


and custom logs.

• Developers use it to debug and track app behavior.

List and explain different Log levels in Android.

Answer:

Method Purpose

Log.e Error

Log.w Warning

Log.i Information

Log.d Debugging details


Log.v Very detailed logs (verbose)

Explain what happens when you rotate an Android device.

Answer:

• Android destroys the current Activity.

• Recreates a new Activity.

• Runs onCreate() again.

• If state-saving methods (onSaveInstanceState()) are used, data is restored.

What is SharedPreferences? When should you use it?

Answer:

• A simple way to store small, key-value data (e.g., login status, user name).

• Used when saving basic settings or flags that persist across app sessions.
SECTION B: Practical (Coding/UI
Questions)

43 16. Create a simple Login Screen XML layout with two EditTexts
(Username, Password) and a Button.

44 Answer:
How to open a second Activity when Button is clicked? Write Java/Kotlin
Code.

Answer:
Design a UI with a Spinner (Dropdown) and a Submit Button.

Answer:

Write the Java/Kotlin code to show a Toast message when a button is clicked.

Answer:
How to save the username entered in EditText using SharedPreferences?

Answer:

This saves the username safely even if the app closes.

You might also like