0% found this document useful (0 votes)
28 views18 pages

Android Notifications, Menus, and Dialogs Guide

Chapter 2 covers key components of Android app development including intents, notifications, menus, and dialogs. It explains how intents facilitate communication between components, how notifications inform users of events, and the different types of menus and dialogs used for user interaction. Additionally, it discusses the importance of localization in adapting apps for diverse audiences, emphasizing translation and cultural adaptation.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views18 pages

Android Notifications, Menus, and Dialogs Guide

Chapter 2 covers key components of Android app development including intents, notifications, menus, and dialogs. It explains how intents facilitate communication between components, how notifications inform users of events, and the different types of menus and dialogs used for user interaction. Additionally, it discusses the importance of localization in adapting apps for diverse audiences, emphasizing translation and cultural adaptation.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

Chapter 2:

NOTIFICATION, MENUS AND


DIALOGS
Contents:

 Intents with parameter


 Notification with status bar and toast
 Localization
 Context/option menu
 Alert dialog
 Dialog as activity
Intents

 Intents are messages used to request actions


from another component
Used for:
 Starting Activities
 Starting Services
 Broadcasting events
 Two types:
 Explicit Intent : open specific activity
 Implicit Intent : open external apps
Notifications

A notification is a message that Android


apps display outside the app’s UI, usually in
the status bar and notification drawer, to
inform users about important events.
Example:
WhatsApp: When you receive a new
message, WhatsApp shows a notification in
your phone’s notification area with a preview
of the message and sender. You can tap the
notification to open the chat directly.
Sample java code snippet:

[Link] builder = new


[Link](this, "channel_id")
.setSmallIcon([Link].ic_message)
.setContentTitle("New Message")
.setContentText("John: Hey, are you coming
tonight?")
.setPriority(NotificationCompat.PRIORITY_HIGH);

NotificationManagerCompat notificationManager =
[Link](this);
[Link](1001, [Link]());
Menus
 Menus are UI elements that display options or actions to users, typically in the
app bar or as popups.
 Types of Menus:
1. Options menu: Main actions for the activity.
 Is used for actions that have a global impact on the app, such as settings, search, or logout.
2. Context menu: Actions related to a specific item (appears on long-press).
 A floating menu that appears when the user performs a long press on a
specific UI element (like a list item or an image).
 It provides actions that are relevant to the selected content or context.
 The Contextual Action Mode offers a more integrated experience, where
an action bar appears at the top of the screen with actions related to the
selected item(s).
3. Popup menu: Temporary menu anchored to a view.
 This menu displays a list of items in a vertical list, anchored/attached
to a specific View that invoked it.
Menus…

Real-world Example:
Gmail: The three-dot icon in the top-right corner opens a
menu with options like "Settings", "Help", or "Send
feedback".
File Manager: Long-pressing a file opens a context menu
with options like "Copy", "Delete", or "Rename".
Sample XML for options menu

<menu
xmlns:android="[Link]
k/res/android">
<item android:id="@+id/action_settings"
android:title="Settings" />
<item android:id="@+id/action_logout"
android:title="Logout" />
</menu>
Dialogs

A dialog is a small window that asks the user to make a


decision or enter additional information. It interrupts
the current flow without taking over the whole screen.
Types of Dialogs:
1. Alert dialog: Messages, confirmations, choices.
2. Date/Time picker dialog: Select a date or time.
3. Custom dialog: Any layout you design.
Real-world Example:
Deleting an Email in Gmail: When you tap "Delete", a
dialog asks, “Are you sure you want to delete this
message?” with "Cancel" and "OK" options.
Booking Apps: When booking a ticket, a dialog might
pop up to confirm details before proceeding.
Sample java code for a confirmation
dialog:

new [Link](this)
.setTitle("Delete Email")
.setMessage("Are you sure you want to delete this
email?")
.setPositiveButton("Delete", (dialog, which) -> {
// Code to delete email
})
.setNegativeButton("Cancel", null)
.show();
Summary Table
Notification with status bar and
toast

 In mobile operating systems like Android, "notifications with


status bar and toast" refer to two distinct but related methods of
providing user feedback:
1. Status Bar Notifications:
 These are persistent alerts displayed in the device's status bar
(at the top of the screen).
 They typically include an icon and a brief text message.
 When a user pulls down the notification shade, they can see
more details about the notification and often interact with it
(e.g., open the associated app, dismiss the notification).
 Status bar notifications are used for important events that the
user needs to be aware of and potentially act upon, such as new
messages, incoming calls, or background process updates.
 They remain visible until the user dismisses them or the
associated event is resolved.
2. Toast Notifications

These are temporary, non-interactive messages


that appear briefly on the screen, usually at the
bottom, and then automatically fade away after a
short duration (e.g., a few seconds).
Toasts are typically used for providing quick,
subtle feedback about an operation or system
message that doesn't require immediate user
interaction.
Examples include "Message sent," "Item added to
cart," or "Network connection lost." They are not
persistent and do not appear in the status bar or
notification shade.
Key Differences

 Persistence:
 Status bar notifications are persistent until dismissed, while
toasts are temporary and self-dismissing.
 Location:
 Status bar notifications appear in the status bar and
notification shade, while toasts appear as a transient(lasting
only for a short time) overlay on the screen.
 Interactivity:
 Status bar notifications can often be interacted with (e.g.,
tapping to open an app), while toasts are generally non-
interactive.
 Purpose:
 Status bar notifications are for important, actionable events,
while toasts are for brief, non-critical feedback.
Localization

Android application localization is the process of


adapting an Android application to meet the linguistic,
cultural, and technical requirements of a specific
target market or locale.
Android runs on many devices in many regions. To
reach the most users, make sure that your app
handles text, audio files, numbers, currency, and
graphics in ways appropriate to the locales where
your app is used.
This goes beyond simple translation and involves a
comprehensive approach to ensure the app is relevant
and user-friendly for diverse audiences worldwide.
Key area of Android app localization

1. Translation of Textual Content:


 Translating all user-facing text, such as strings, labels, buttons, menus,
and descriptions, into the target language(s).
 This is typically done by creating separate [Link] files for each
locale within the res/values-locale directory.
2. Cultural Adaptation:
 Adjusting elements like date and time formats, number and currency

formats, units of measurement, and potentially even color schemes


or imagery to align with cultural norms and preferences of the target
locale.
3. Layout and UI Adjustments:
 Designing layouts that can accommodate varying text lengths in

different languages, preventing text truncation or excessive spacing.


 This often involves using flexible layouts and avoiding fixed

dimensions for UI elements. Example:


Key area of Android app
localization…

4. Localization of Media:
 Adapting or replacing images, icons, audio files, and
videos to ensure cultural appropriateness and relevance.

By implementing comprehensive localization, Android


developers can expand their app's reach, improve user
engagement, and create a more inclusive experience for a
global audience.
End of the Chapter

THANKS
!

You might also like