Chapter Two
Notification, Menus, and Dialogs
Content
Intents with Parameters
Notifications (Status Bar & Toast)
Localization
Context/Option Menu
Intents with Parameters
• An Intent in Android is a messaging object
used to request an action from another app
component.
• It allows communication between different
components such as activities, services, and
broadcast receivers.
Types of Intents
• Explicit Intent: Used to start a specific
component (e.g., start a new activity within
the same application).
• Implicit Intent: Used when the component is
not explicitly defined (e.g., sharing data with
another app).
Cont’d…
• Passing Parameters with Intents
• To pass data between activities, we use
[Link]() method:
To retrieve the data in the new activity:
Notification with Status Bar and Toast
Notification
•A Notification is a message displayed outside
the application's UI to provide updates or
reminders to the user.
Creating a Notification
Toast Notification:
– Short-lived messages that appear at
the bottom of the screen.
– Example:
Localization and Usage
•Adapting an app to different languages and regions.
•Key Components:
•Implementation:
• Usage:
Context/Option Menu
• Context Menu:
– Appears when the user performs a long press on
an item.
– Example:
Context Menu
• It appears when the user performs a long-
press (press and hold) on a UI element.
• It is typically used for contextual actions, such
as editing or deleting an item.
Options Menu
• It is a primary menu in Android that appears
in the app bar (toolbar).
• It provides quick access to frequently used
actions such as settings, search, logout, or
help.
Steps to Implement an Options Menu
1. Create the Menu XML File
The menu items are defined in an XML file inside the
res/menu/ directory.
📁 Path: res/menu/menu_main.xml
<menu xmlns:android="[Link]
<item android:id="@+id/action_settings" android:title="Settings"
android:icon="@android:drawable/ic_menu_preferences"
android:showAsAction="never" /> <item
android:id="@+id/action_about" android:title="About"
android:showAsAction="never" />
</menu>
Alert Dialog
• It is used to display an alert message with
optional actions.
• It is a type of activity in Android that behaves
like a dialog rather than a full-screen window.
• It is useful for displaying temporary
information, getting user input, or confirming
actions without disrupting the user’s
workflow.
Key Features:
•Appears as a floating window.
•Does not occupy the entire screen.
•Can be themed to look like a dialog.
Dialog as Activity
• Instead of using AlertDialog, you can create a
custom dialog using an Activity with a dialog
theme.
• Steps to Create a Dialog as an Activity
1. Create a new Activity with a Dialog theme in
[Link]:
2Create the Dialog Activity Layout
(res/layout/dialog_activity.xml)
Cont’d….
3. Start the Dialog Activity
4. Implement UI and logic in [Link]
• 2. Implement UI and logic in [Link]