Prepared By : Prof. Uday Shah (HOD-IT)
Android Terminologies
Android Terminologies
• Context
-
Context
is an abstract class in Android used to access application-specific resources and classes. -
It provides access to application environment data like databases, shared preferences, and system services.
-
Activities, Services, and Applications are subclasses of Context.
-
It is essential to start components like activities or services using
startActivity()
orstartService()
. -
Context is required to access resources via
getResources()
or launch a Toast message. -
There are two main types:
Application Context
andActivity Context
. -
Application Context
is tied to the application lifecycle, whileActivity Context
is tied to the activity lifecycle. -
Misuse of context can lead to memory leaks, especially if you hold references to activity context in static objects.
-
It helps in inflating views using
LayoutInflater
. -
Context is often passed to classes and adapters that require access to resources.
• Activity
-
Activity
is a single screen with a user interface in an Android application. -
It is the entry point for interacting with the user and handling UI events.
-
Each activity goes through a lifecycle:
onCreate()
,onStart()
,onResume()
,onPause()
,onStop()
,onDestroy()
. -
Defined in the AndroidManifest.xml to be recognized by the system.
-
An app may contain multiple activities for different screens or functions.
-
Activities can launch other activities using intents.
-
They manage fragments and support multitasking with the back stack.
-
UI for an activity is usually defined in an XML layout file.
-
The activity manages the user input and interaction logic.
-
It plays a central role in UI design and navigation in Android.
• Intent
-
Intent
is a messaging object used to request an action from another app component. -
Intents are used to start activities, start services, and broadcast messages.
-
There are two types: Explicit Intent (targets a specific component) and Implicit Intent (asks system to find component).
-
Intents can carry data using extras (
putExtra()
,getExtra()
). -
They are used to open system components (camera, browser, etc.).
-
Intent Filters are declared in the manifest to handle implicit intents.
-
It enables component reusability and communication between components.
-
Intents are also used for navigation between screens.
-
startActivityForResult()
uses intent to get results back from another activity. -
Proper use of intents improves modularity and inter-app communication.
• Service
-
Service
is an Android component used to perform background operations. -
It does not provide a user interface.
-
Useful for long-running tasks like downloading files, playing music, or network calls.
-
Services can be started (
startService()
) or bound (bindService()
). -
onStartCommand()
is called when a service is started. -
Services continue to run even if the user switches activities.
-
Android provides Foreground Services to indicate ongoing tasks to users.
-
Must be stopped using
stopSelf()
orstopService()
to avoid resource leakage. -
Services can run on the main thread, but for heavy operations, use
IntentService
orWorkManager
. -
Properly managing services is essential to optimize battery and performance.
• Broadcast Receiver
-
BroadcastReceiver
allows apps to listen for and respond to broadcast messages from the system or other apps. -
Common system broadcasts include battery low, connectivity changes, or boot completed.
-
You can define a broadcast receiver by extending
BroadcastReceiver
and overridingonReceive()
. -
Receivers can be registered statically in the manifest or dynamically in code.
-
Used for receiving messages in the background without UI.
-
Receivers are often used with alarms or scheduled tasks.
-
They are lightweight and should do quick processing only.
-
For longer tasks, use a service inside
onReceive()
to offload the work. -
They help apps stay reactive to system-level changes.
-
Security is important; define permissions if needed to restrict broadcasts.
• Fragment
-
A
Fragment
represents a reusable portion of the user interface inside an activity. -
It has its own lifecycle, separate from the activity, but still tied to it.
-
Multiple fragments can be combined in one activity to support multi-pane UI (like in tablets).
-
Defined using XML or Java/Kotlin and added via FragmentManager.
-
Common lifecycle methods:
onAttach()
,onCreateView()
,onStart()
,onResume()
, etc. -
Allows modular design and code reuse between activities.
-
Communicates with its host activity using interfaces or ViewModel (in MVVM pattern).
-
Fragments can be dynamically added, removed, or replaced during runtime.
-
Supports back stack navigation.
-
They are essential for building responsive UIs for various screen sizes.
-
Fragments improve app flexibility and adaptability.
Resources
• Working with Different Types of Resources:
➤ String
-
Defined in
res/values/strings.xml
. -
Used for text values like labels, messages, and UI text.
-
Accessed in code using
getString(R.string.name)
. -
Supports localization and easy maintenance of text.
-
Reduces hardcoding in Java/Kotlin code.
-
Enables translation of app into multiple languages.
-
Placeholders (
%s
,%d
) allow formatted strings. -
Best practice to define all UI text in strings.xml.
-
Reduces redundancy and increases code clarity.
-
Can be used in XML layouts using
@string/name
.
➤ Integer
-
Stored in
res/values/integers.xml
. -
Used for numeric constants, dimensions, or configuration values.
-
Accessed using
getResources().getInteger(R.integer.value_name)
. -
Helps in reusing numeric values across the app.
-
Useful for app settings or UI configurations.
-
Integer arrays can also be defined and used in adapters.
-
Avoids magic numbers in code.
-
Encourages better maintainability.
-
Supports device-specific tuning if placed in resource qualifiers.
-
Helps separate logic from configuration.
➤ Drawable
-
Used for images, shapes, vectors, and graphic content.
-
Stored in the
res/drawable
folder. -
Can include
.png
,.jpg
,.xml
vector files or shape drawables. -
Used in backgrounds, buttons, icons, etc.
-
Custom shapes can be defined using XML (rectangle, gradient).
-
Used in layout via
android:background="@drawable/image"
. -
Easily scalable across screen densities.
-
Android Studio supports vector drawables for performance.
-
Helps create consistent and visually rich UIs.
-
Can be animated using drawable animation.
➤ Color
-
Stored in
res/values/colors.xml
. -
Defines app color palette using HEX values.
-
Used in UI elements like buttons, backgrounds, and text.
-
Can be accessed in code (
ContextCompat.getColor()
) and XML (@color/name
). -
Supports theming and material design.
-
Encourages reuse and consistency of color across the app.
-
Helps in applying night mode using color state lists.
-
Different resources can be defined for light/dark mode.
-
Used in defining themes and styles.
-
Improves UI aesthetics and accessibility.
➤ Style
-
Stored in
res/values/styles.xml
. -
Defines appearance attributes for UI elements.
-
Helps in applying consistent look across multiple views.
-
Used to define font size, padding, colors, etc.
-
Reduces redundancy in layout files.
-
Supports inheritance using
parent
attribute. -
Can be applied in layouts using
style="@style/StyleName"
. -
Encouraged for scalable and maintainable UI.
-
Promotes adherence to Material Design Guidelines.
-
Themes can be created using styles for full-app customization.
Animation
• Tween Animation
-
Tween (in-between) animation modifies an object’s properties over time.
-
Includes effects like translate, rotate, scale, and fade (alpha).
-
Defined in XML inside
res/anim
folder. -
Applies to Views and starts using
startAnimation()
. -
Lightweight and does not affect view's actual position or state.
-
Example: A button slides in from the left.
-
Useful for basic visual effects in UI.
-
Does not allow complex frame changes or drawable switching.
-
Can be chained using animation sets.
-
Commonly used in splash screens and transitions.
• Frame-by-Frame Animation
-
Displays a sequence of drawable images (like a flipbook).
-
Defined using
AnimationDrawable
in XML (res/drawable/animation_list.xml
). -
Each frame has a duration, and animation loops or stops.
-
Suitable for animations like loading indicators or cartoons.
-
Starts using
start()
method in Java/Kotlin. -
Requires multiple drawable resources (images).
-
Heavier on memory compared to tween.
-
Can simulate realistic animations.
-
Often used in games or fun visual effects.
-
Should manage resource cleanup to avoid memory issues.
:: Best of Luck ::