Mobile Application Development
Activity & Services
Android User Interfaces
1. Activities
2. Layouts
3. Menus
4. Dialogs
5. Intents
6. Notifications
Creating an Activity
• Create a new Activity by extending the Activity class.
• Override the onCreate() method to set the view for the
activity
• Set the user interface to an Activity using the
setContentView() method in the onCreate method of
the Activity.
public class MyActivity extends Activity {
public void onCreate(Bundle b) {
super.onCreate(b);
setContentView(R.layout.main);
}
}
• Activities in the system are managed as an activity stack.
• The Android memory manager uses this stack to determine
the priority of applications based on their Activities when
deciding which application to terminate to free resources.
• An activity has essentially four states:
 Active : An activity in the foreground of the screen.
 Paused : An activity has lost focus but is still visible.
 Stopped : An activity is completely obscured by another
activity.
 Inactive : After an Activity has been killed or before it has
been launched.
Activity Life Cycle
Android - Activity, Services
Activity Lifetimes
• Entire lifetime :
Happens between the first call to onCreate(Bundle) through
to a single final call to onDestroy(). An activity will do all
setup of "global" state in onCreate(), and release all remaining
resources in onDestroy().
• Visible lifetime :
Happens between a call to onStart() until a corresponding call
to onStop(). During this time the user can see the activity on-
screen, though it may not be in the foreground and
interacting with the user.
• Foreground lifetime :
Happens between a call to onResume() until a corresponding
call to onPause().
Layouts
• Layout is the design plan or the architecture for the
user interface in an activity.
• Layout is required to arrange or organize the widgets
inside an activity.
• Layout defines the activity structure & holds all the
elements that are part of the user interface.
• Layouts can be nested.
A Layout can be declared in two ways:
• Declaring in XML:
Android provides a straightforward XML tags that
corresponds to the View classes and subclasses, such as
those for widgets and layouts that can be added to the
layout.
• Instantiating at runtime:
Your application can create View and ViewGroup objects
(and manipulate their properties) programmatically.
Declaring Layout
• Linear Layout
A layout that organizes its children into a single horizontal or
vertical row.
• Table Layout
A layout that positions its children into rows and columns.
• Relative Layout
A layout that allows to organize child elements in positions
relative to the parent or siblings elements.
• Frame Layout
It is designed to block out an area on the screen to display a
single item.
Layout Types
Android - Activity, Services
Menus
• Menus provide familiar interfaces to expose
application functions without sacrificing screen
space.
• Android offers an easy programming interface to
provide standardized application menus.
• Android offers three fundamental types of
application menus:
 Options Menu
 Context Menu
 Sub-menu
• By default, every Activity supports an Options menu. It
is revealed by pressing the device MENU key.
• Options Menu has two groups of menu items:
Icon Menu
 Collection of maximum of six menu items
 Supports Icons and short-cuts
Expanded Menu
 Exposed by the 'More' menu item
 Displayed when the icon menu becomes over-loaded
 Comprised of sixth options menu item and the rest.
Options Menu
Options Menu
Context Menu
• Context menu is a floating menu that is associated
with a control.
• Context menu is launched when the control has the
focus and the D pad is pressed.
• Context menus can be assigned to any View within
an Activity.
• It provides functions relating to the view, to which it
is registered.
• It supports submenus, checkboxes, radio buttons.
• It does not support shortcuts and icons.
Context Menu
• Sub menu is a floating menu, it can be a child menu of
options menu or context menu.
• It supports checkboxes, radio buttons and shortcut
keys.
• It does not support item icons, or nested sub menus.
Sub Menu
Sub Menu
• A dialog is a small window that appears in front of an
Activity.
• The underlying Activity loses focus and the dialog
accepts all user interaction.
• Normally used for notifications and short activities that
directly relate to the application in progress.
• Android supports following types of dialogs.
Alert Dialog
Progress Dialog
Date Picker Dialog
Time Picker Dialog
Toast
Dialog
• A dialog that can manage zero, one, two or three
buttons.
• It can also manage a list of selectable items that can
include checkboxes or radio buttons.
• The AlertDialog is capable of constructing most
dialog user interfaces and is the suggested dialog
type.
• AlertDialog class is a subclass of Dialog class and
has a nested subclass AlertDialog.Builder to
construct a dialog.
Alert Dialog
Android - Activity, Services
Other Dialogs
• Progress Dialog
A dialog that displays a progress wheel or progress
bar.
It supports buttons like in AlertDialog.
• DatePicker Dialog
A dialog that allows the user to select a date.
• TimePicker Dialog
A dialog that allows the user to select a time.
Android - Activity, Services
• A toast is a transient Dialog box containing a
quick little message for the user.
• Toasts never receive focus and they don’t
interrupt the active application.
• They provide an ideal mechanism for alerting
users to events occurring in background Services
without interrupting foreground applications.
Toast
• Intents are the messages that are used to activate
following application components:
Activities
Services
Broadcast Receivers
• Intent is an object, which has a data structure holding
any one of the following data :
Abstract description of an operation to be performed
In the case of broadcasts, a description of something
that has happened and is being announced.
Intents
Application components are invoked through intents
in the following way :
• Activity : Intent object is passed to following
functions to invoke the Activity.
Context.startActivity (Intent intent)
Activity.startActivityForResult (Intent intent, int
requestCode)
• Service : Intent object is passed to following functions
to invoke the Service.
Context.startService (Intent)
Context.bindService (Intent)
Invoking Components
• Broadcast Receivers : Intent object is passed to
following functions to invoke the Broadcast
Receiver.
 Context.sendBroadcast ( Intent intent, String
receiverPermission)
 Context.sendOrderedBroadcast ( Intent intent,
String receiverPermission)
 Context.sendStickyBroadcast ( Intent intent )
Invoking Components
• A status bar notification adds an icon to the system's
status bar (with an optional ticker-text message) and an
expanded message in the "Notifications" window.
• When the user selects the expanded message, Android
fires an Intent that is defined by the notification
(usually to launch an Activity).
• You can also configure the notification to alert the user
with a sound, a vibration, and flashing lights on the
device.
• This kind of notification is ideal when your application
is working in a background Service and needs to notify
the user about an event.
Notification
• To create a notification, following classes should be
used:
Notification
NotificationManager
• Notification is a class that represents how a persistent
notification is to be presented to the user using the
NotificationManager.
• NotificationManager is an Android system service used
to handle notifications.
Notification (Continued)
Notification (Continued)
Notification (Continued)
• A Service is an application component that runs in the
background for an indefinite period of time.
• Services are specifically used to handle operations and
functionality that should run silently, without any User
Interface.
• Services are generally used to perform following
operations in the background
 Updating the Content Providers
 Firing Intents
 Triggering Notifications etc
• Services, like other application objects, run in the main
thread of their hosting process.
Services
• Services are started, stopped, and controlled from
other application components including other
Services, Activities, and Broadcast Receivers.
• Service is involved in any CPU intensive (such as MP3
playback) or blocking (such as networking)
operations, should spawn its own thread to do that
work.
• Android platform has following services:
 Location Manager
 Media Controller
 Notification Manager
Services (Continued)
• Service supports following lifecycle methods :
 OnCreate
 OnStart
 OnBind
 OnUnbind
 OnRebind
 OnDestroy
• Service is controlled using following methods:
 Context.startService
 Context.stopService
 Service.stopSelf
 Context.bindService
 Context.UnbindService
Service Life Cycle
Android - Activity, Services
1. Professional Android Application Development, Reto
Meier, Wrox, November 2008
2. Beginning Android, Mark Murphy, Apress, June 2009
3. Pro Android, Sayed Y Hashimi, Apress, June 2009
4. Android – Application Development, Rick Rogers et.al,
O’Reilly, May 2009
5. “Hello, Android”, Introducing Google’s Mobile
Development Platform, Ed Burnette, The Pragmatic
Bookshelf, 2008
6. developer.android.com
References

More Related Content

PPTX
Google android Activity lifecycle
PPTX
Android activity lifecycle
PPTX
Presentation on Android application life cycle and saved instancestate
PPT
Android lifecycle
PPT
android activity
PPTX
Activity lifecycle
PDF
Android life cycle
PPT
Android tutorial (2)
Google android Activity lifecycle
Android activity lifecycle
Presentation on Android application life cycle and saved instancestate
Android lifecycle
android activity
Activity lifecycle
Android life cycle
Android tutorial (2)

What's hot (8)

PDF
Mad textbook 63-116
PDF
Android activities & views
PDF
Unit-3 event handling
PPTX
Lecture #4 activities & fragments
PPTX
Event handling in Java(part 1)
PPT
Java Event Handling
PPT
Unit 11. Objects and machines
PDF
JAVA GUI PART III
Mad textbook 63-116
Android activities & views
Unit-3 event handling
Lecture #4 activities & fragments
Event handling in Java(part 1)
Java Event Handling
Unit 11. Objects and machines
JAVA GUI PART III
Ad

Similar to Android - Activity, Services (20)

PPTX
App Fundamentals and Activity life cycle.pptx
PPTX
11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptx
PPTX
Introduction to Android Development
PDF
Android Development Tutorial
PPTX
Data Transfer between activities and Database
PPTX
Data Transfer between Activities & Databases
PDF
MAD Unit - 2 Activity and Fragment Management in Android (Diploma IT)
PDF
Embedded Systems.pdf
PPTX
Basics 4
PPTX
B2. activity and intent
PPT
Android architecture
PDF
Android activity
PDF
Android activity
PPTX
Android Application Development
PPTX
Andriod Lecture 8 A.pptx
PPTX
W2_Lec03_Lec_04_Activity.pptx
PPTX
02. Android application development_Lec2.pptx
PPTX
Notes Unit3.pptx
PPTX
User interface design elements.pptx fyiiyyj
PDF
Introduction of Xcode
App Fundamentals and Activity life cycle.pptx
11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptx
Introduction to Android Development
Android Development Tutorial
Data Transfer between activities and Database
Data Transfer between Activities & Databases
MAD Unit - 2 Activity and Fragment Management in Android (Diploma IT)
Embedded Systems.pdf
Basics 4
B2. activity and intent
Android architecture
Android activity
Android activity
Android Application Development
Andriod Lecture 8 A.pptx
W2_Lec03_Lec_04_Activity.pptx
02. Android application development_Lec2.pptx
Notes Unit3.pptx
User interface design elements.pptx fyiiyyj
Introduction of Xcode
Ad

More from Dr Karthikeyan Periasamy (9)

PDF
Web tools - angular js
PDF
PDF
System thinking about system
PPTX
Android Database
PPTX
Android Introduction
PPTX
Arduino Programming
PPTX
Internet of Things
PDF
Padlet Creation
PDF
Canvas LMS Creation
Web tools - angular js
System thinking about system
Android Database
Android Introduction
Arduino Programming
Internet of Things
Padlet Creation
Canvas LMS Creation

Recently uploaded (9)

DOC
SIUE毕业证学历认证,阿祖萨太平洋大学毕业证学位证书复制
PPTX
Social Media People PowerPoint Templates.pptx
PDF
Date Right Stuff - Invite only, conservative dating app
PDF
Kids, Screens & Emotional Development by Meenakshi Khakat
PPTX
Introduction to Packet Tracer Course Overview - Aug 21 (1).pptx
PDF
Best 4 Sites for Buy Verified Cash App Accounts – BTC Only.pdf
DOC
NIU毕业证学历认证,阿比林基督大学毕业证留学生学历
PDF
2025 Guide to Buy Verified Cash App Accounts You Can Trust.pdf
DOC
EIU毕业证学历认证,贝尔维尤学院毕业证国外毕业证
SIUE毕业证学历认证,阿祖萨太平洋大学毕业证学位证书复制
Social Media People PowerPoint Templates.pptx
Date Right Stuff - Invite only, conservative dating app
Kids, Screens & Emotional Development by Meenakshi Khakat
Introduction to Packet Tracer Course Overview - Aug 21 (1).pptx
Best 4 Sites for Buy Verified Cash App Accounts – BTC Only.pdf
NIU毕业证学历认证,阿比林基督大学毕业证留学生学历
2025 Guide to Buy Verified Cash App Accounts You Can Trust.pdf
EIU毕业证学历认证,贝尔维尤学院毕业证国外毕业证

Android - Activity, Services

  • 2. Android User Interfaces 1. Activities 2. Layouts 3. Menus 4. Dialogs 5. Intents 6. Notifications
  • 3. Creating an Activity • Create a new Activity by extending the Activity class. • Override the onCreate() method to set the view for the activity • Set the user interface to an Activity using the setContentView() method in the onCreate method of the Activity. public class MyActivity extends Activity { public void onCreate(Bundle b) { super.onCreate(b); setContentView(R.layout.main); } }
  • 4. • Activities in the system are managed as an activity stack. • The Android memory manager uses this stack to determine the priority of applications based on their Activities when deciding which application to terminate to free resources. • An activity has essentially four states:  Active : An activity in the foreground of the screen.  Paused : An activity has lost focus but is still visible.  Stopped : An activity is completely obscured by another activity.  Inactive : After an Activity has been killed or before it has been launched. Activity Life Cycle
  • 6. Activity Lifetimes • Entire lifetime : Happens between the first call to onCreate(Bundle) through to a single final call to onDestroy(). An activity will do all setup of "global" state in onCreate(), and release all remaining resources in onDestroy(). • Visible lifetime : Happens between a call to onStart() until a corresponding call to onStop(). During this time the user can see the activity on- screen, though it may not be in the foreground and interacting with the user. • Foreground lifetime : Happens between a call to onResume() until a corresponding call to onPause().
  • 7. Layouts • Layout is the design plan or the architecture for the user interface in an activity. • Layout is required to arrange or organize the widgets inside an activity. • Layout defines the activity structure & holds all the elements that are part of the user interface. • Layouts can be nested.
  • 8. A Layout can be declared in two ways: • Declaring in XML: Android provides a straightforward XML tags that corresponds to the View classes and subclasses, such as those for widgets and layouts that can be added to the layout. • Instantiating at runtime: Your application can create View and ViewGroup objects (and manipulate their properties) programmatically. Declaring Layout
  • 9. • Linear Layout A layout that organizes its children into a single horizontal or vertical row. • Table Layout A layout that positions its children into rows and columns. • Relative Layout A layout that allows to organize child elements in positions relative to the parent or siblings elements. • Frame Layout It is designed to block out an area on the screen to display a single item. Layout Types
  • 11. Menus • Menus provide familiar interfaces to expose application functions without sacrificing screen space. • Android offers an easy programming interface to provide standardized application menus. • Android offers three fundamental types of application menus:  Options Menu  Context Menu  Sub-menu
  • 12. • By default, every Activity supports an Options menu. It is revealed by pressing the device MENU key. • Options Menu has two groups of menu items: Icon Menu  Collection of maximum of six menu items  Supports Icons and short-cuts Expanded Menu  Exposed by the 'More' menu item  Displayed when the icon menu becomes over-loaded  Comprised of sixth options menu item and the rest. Options Menu
  • 14. Context Menu • Context menu is a floating menu that is associated with a control. • Context menu is launched when the control has the focus and the D pad is pressed. • Context menus can be assigned to any View within an Activity. • It provides functions relating to the view, to which it is registered. • It supports submenus, checkboxes, radio buttons. • It does not support shortcuts and icons.
  • 16. • Sub menu is a floating menu, it can be a child menu of options menu or context menu. • It supports checkboxes, radio buttons and shortcut keys. • It does not support item icons, or nested sub menus. Sub Menu
  • 18. • A dialog is a small window that appears in front of an Activity. • The underlying Activity loses focus and the dialog accepts all user interaction. • Normally used for notifications and short activities that directly relate to the application in progress. • Android supports following types of dialogs. Alert Dialog Progress Dialog Date Picker Dialog Time Picker Dialog Toast Dialog
  • 19. • A dialog that can manage zero, one, two or three buttons. • It can also manage a list of selectable items that can include checkboxes or radio buttons. • The AlertDialog is capable of constructing most dialog user interfaces and is the suggested dialog type. • AlertDialog class is a subclass of Dialog class and has a nested subclass AlertDialog.Builder to construct a dialog. Alert Dialog
  • 21. Other Dialogs • Progress Dialog A dialog that displays a progress wheel or progress bar. It supports buttons like in AlertDialog. • DatePicker Dialog A dialog that allows the user to select a date. • TimePicker Dialog A dialog that allows the user to select a time.
  • 23. • A toast is a transient Dialog box containing a quick little message for the user. • Toasts never receive focus and they don’t interrupt the active application. • They provide an ideal mechanism for alerting users to events occurring in background Services without interrupting foreground applications. Toast
  • 24. • Intents are the messages that are used to activate following application components: Activities Services Broadcast Receivers • Intent is an object, which has a data structure holding any one of the following data : Abstract description of an operation to be performed In the case of broadcasts, a description of something that has happened and is being announced. Intents
  • 25. Application components are invoked through intents in the following way : • Activity : Intent object is passed to following functions to invoke the Activity. Context.startActivity (Intent intent) Activity.startActivityForResult (Intent intent, int requestCode) • Service : Intent object is passed to following functions to invoke the Service. Context.startService (Intent) Context.bindService (Intent) Invoking Components
  • 26. • Broadcast Receivers : Intent object is passed to following functions to invoke the Broadcast Receiver.  Context.sendBroadcast ( Intent intent, String receiverPermission)  Context.sendOrderedBroadcast ( Intent intent, String receiverPermission)  Context.sendStickyBroadcast ( Intent intent ) Invoking Components
  • 27. • A status bar notification adds an icon to the system's status bar (with an optional ticker-text message) and an expanded message in the "Notifications" window. • When the user selects the expanded message, Android fires an Intent that is defined by the notification (usually to launch an Activity). • You can also configure the notification to alert the user with a sound, a vibration, and flashing lights on the device. • This kind of notification is ideal when your application is working in a background Service and needs to notify the user about an event. Notification
  • 28. • To create a notification, following classes should be used: Notification NotificationManager • Notification is a class that represents how a persistent notification is to be presented to the user using the NotificationManager. • NotificationManager is an Android system service used to handle notifications. Notification (Continued)
  • 31. • A Service is an application component that runs in the background for an indefinite period of time. • Services are specifically used to handle operations and functionality that should run silently, without any User Interface. • Services are generally used to perform following operations in the background  Updating the Content Providers  Firing Intents  Triggering Notifications etc • Services, like other application objects, run in the main thread of their hosting process. Services
  • 32. • Services are started, stopped, and controlled from other application components including other Services, Activities, and Broadcast Receivers. • Service is involved in any CPU intensive (such as MP3 playback) or blocking (such as networking) operations, should spawn its own thread to do that work. • Android platform has following services:  Location Manager  Media Controller  Notification Manager Services (Continued)
  • 33. • Service supports following lifecycle methods :  OnCreate  OnStart  OnBind  OnUnbind  OnRebind  OnDestroy • Service is controlled using following methods:  Context.startService  Context.stopService  Service.stopSelf  Context.bindService  Context.UnbindService Service Life Cycle
  • 35. 1. Professional Android Application Development, Reto Meier, Wrox, November 2008 2. Beginning Android, Mark Murphy, Apress, June 2009 3. Pro Android, Sayed Y Hashimi, Apress, June 2009 4. Android – Application Development, Rick Rogers et.al, O’Reilly, May 2009 5. “Hello, Android”, Introducing Google’s Mobile Development Platform, Ed Burnette, The Pragmatic Bookshelf, 2008 6. developer.android.com References