SlideShare a Scribd company logo
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
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
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
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.
• 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
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

What's hot

Mad textbook 63-116
Mad textbook 63-116Mad textbook 63-116
Mad textbook 63-116
PrathishGM
 
Android activities & views
Android activities & viewsAndroid activities & views
Android activities & views
ma-polimi
 
Unit-3 event handling
Unit-3 event handlingUnit-3 event handling
Unit-3 event handling
Amol Gaikwad
 
Lecture #4 activities & fragments
Lecture #4  activities & fragmentsLecture #4  activities & fragments
Lecture #4 activities & fragments
Vitali Pekelis
 
Event handling in Java(part 1)
Event handling in Java(part 1)Event handling in Java(part 1)
Event handling in Java(part 1)
RAJITHARAMACHANDRAN1
 
Java Event Handling
Java Event HandlingJava Event Handling
Java Event Handling
Shraddha
 
Unit 11. Objects and machines
Unit 11. Objects and machinesUnit 11. Objects and machines
Unit 11. Objects and machines
lolijisa
 
JAVA GUI PART III
JAVA GUI PART IIIJAVA GUI PART III
JAVA GUI PART III
OXUS 20
 

What's hot (8)

Mad textbook 63-116
Mad textbook 63-116Mad textbook 63-116
Mad textbook 63-116
 
Android activities & views
Android activities & viewsAndroid activities & views
Android activities & views
 
Unit-3 event handling
Unit-3 event handlingUnit-3 event handling
Unit-3 event handling
 
Lecture #4 activities & fragments
Lecture #4  activities & fragmentsLecture #4  activities & fragments
Lecture #4 activities & fragments
 
Event handling in Java(part 1)
Event handling in Java(part 1)Event handling in Java(part 1)
Event handling in Java(part 1)
 
Java Event Handling
Java Event HandlingJava Event Handling
Java Event Handling
 
Unit 11. Objects and machines
Unit 11. Objects and machinesUnit 11. Objects and machines
Unit 11. Objects and machines
 
JAVA GUI PART III
JAVA GUI PART IIIJAVA GUI PART III
JAVA GUI PART III
 

Similar to Android - Activity, Services

11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptx
11.11.2020 - Unit 5-3  ACTIVITY, MENU AND SQLITE DATABASE.pptx11.11.2020 - Unit 5-3  ACTIVITY, MENU AND SQLITE DATABASE.pptx
11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptx
MugiiiReee
 
Introduction to Android Development
Introduction to Android DevelopmentIntroduction to Android Development
Introduction to Android Development
Owain Lewis
 
Android Development Tutorial
Android Development TutorialAndroid Development Tutorial
Android Development Tutorial
Germán Bringas
 
Data Transfer between activities and Database
Data Transfer between activities and Database Data Transfer between activities and Database
Data Transfer between activities and Database
faiz324545
 
Data Transfer between Activities & Databases
Data Transfer between Activities & DatabasesData Transfer between Activities & Databases
Data Transfer between Activities & Databases
Muhammad Sajid
 
Embedded Systems.pdf
Embedded Systems.pdfEmbedded Systems.pdf
Embedded Systems.pdf
ruvabebe
 
Basics 4
Basics   4Basics   4
Basics 4
Michael Shrove
 
B2. activity and intent
B2. activity and intentB2. activity and intent
B2. activity and intent
PERKYTORIALS
 
Android architecture
Android architectureAndroid architecture
Android architecture
Deepa Rahul
 
Android activity
Android activityAndroid activity
Android activity
Krazy Koder
 
Android activity
Android activityAndroid activity
Android activity
Krazy Koder
 
Android Application Development
Android Application DevelopmentAndroid Application Development
Android Application Development
Azfar Siddiqui
 
Andriod Lecture 8 A.pptx
Andriod Lecture 8 A.pptxAndriod Lecture 8 A.pptx
Andriod Lecture 8 A.pptx
faiz324545
 
W2_Lec03_Lec_04_Activity.pptx
W2_Lec03_Lec_04_Activity.pptxW2_Lec03_Lec_04_Activity.pptx
W2_Lec03_Lec_04_Activity.pptx
ssuserc1e786
 
Notes Unit3.pptx
Notes Unit3.pptxNotes Unit3.pptx
Notes Unit3.pptx
MIT Autonomous Aurangabad
 
Introduction of Xcode
Introduction of XcodeIntroduction of Xcode
Introduction of Xcode
Dhaval Kaneria
 
Android Activities.pdf
Android Activities.pdfAndroid Activities.pdf
Android Activities.pdf
ssusere71a07
 
Project a day 2 android application fundamentals
Project a day 2   android application fundamentalsProject a day 2   android application fundamentals
Project a day 2 android application fundamentals
Goran Djonovic
 
Ch5 intent broadcast receivers adapters and internet
Ch5 intent broadcast receivers adapters and internetCh5 intent broadcast receivers adapters and internet
Ch5 intent broadcast receivers adapters and internet
Shih-Hsiang Lin
 
Android design patterns in mobile application development presentation
Android design patterns in mobile application development   presentationAndroid design patterns in mobile application development   presentation
Android design patterns in mobile application development presentation
Michail Grigoropoulos
 

Similar to Android - Activity, Services (20)

11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptx
11.11.2020 - Unit 5-3  ACTIVITY, MENU AND SQLITE DATABASE.pptx11.11.2020 - Unit 5-3  ACTIVITY, MENU AND SQLITE DATABASE.pptx
11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptx
 
Introduction to Android Development
Introduction to Android DevelopmentIntroduction to Android Development
Introduction to Android Development
 
Android Development Tutorial
Android Development TutorialAndroid Development Tutorial
Android Development Tutorial
 
Data Transfer between activities and Database
Data Transfer between activities and Database Data Transfer between activities and Database
Data Transfer between activities and Database
 
Data Transfer between Activities & Databases
Data Transfer between Activities & DatabasesData Transfer between Activities & Databases
Data Transfer between Activities & Databases
 
Embedded Systems.pdf
Embedded Systems.pdfEmbedded Systems.pdf
Embedded Systems.pdf
 
Basics 4
Basics   4Basics   4
Basics 4
 
B2. activity and intent
B2. activity and intentB2. activity and intent
B2. activity and intent
 
Android architecture
Android architectureAndroid architecture
Android architecture
 
Android activity
Android activityAndroid activity
Android activity
 
Android activity
Android activityAndroid activity
Android activity
 
Android Application Development
Android Application DevelopmentAndroid Application Development
Android Application Development
 
Andriod Lecture 8 A.pptx
Andriod Lecture 8 A.pptxAndriod Lecture 8 A.pptx
Andriod Lecture 8 A.pptx
 
W2_Lec03_Lec_04_Activity.pptx
W2_Lec03_Lec_04_Activity.pptxW2_Lec03_Lec_04_Activity.pptx
W2_Lec03_Lec_04_Activity.pptx
 
Notes Unit3.pptx
Notes Unit3.pptxNotes Unit3.pptx
Notes Unit3.pptx
 
Introduction of Xcode
Introduction of XcodeIntroduction of Xcode
Introduction of Xcode
 
Android Activities.pdf
Android Activities.pdfAndroid Activities.pdf
Android Activities.pdf
 
Project a day 2 android application fundamentals
Project a day 2   android application fundamentalsProject a day 2   android application fundamentals
Project a day 2 android application fundamentals
 
Ch5 intent broadcast receivers adapters and internet
Ch5 intent broadcast receivers adapters and internetCh5 intent broadcast receivers adapters and internet
Ch5 intent broadcast receivers adapters and internet
 
Android design patterns in mobile application development presentation
Android design patterns in mobile application development   presentationAndroid design patterns in mobile application development   presentation
Android design patterns in mobile application development presentation
 

More from Dr Karthikeyan Periasamy

Web tools - angular js
Web tools - angular jsWeb tools - angular js
Web tools - angular js
Dr Karthikeyan Periasamy
 
System types
System typesSystem types
System thinking about system
System thinking   about systemSystem thinking   about system
System thinking about system
Dr Karthikeyan Periasamy
 
Android Database
Android DatabaseAndroid Database
Android Database
Dr Karthikeyan Periasamy
 
Android Introduction
Android IntroductionAndroid Introduction
Android Introduction
Dr Karthikeyan Periasamy
 
Arduino Programming
Arduino ProgrammingArduino Programming
Arduino Programming
Dr Karthikeyan Periasamy
 
Internet of Things
Internet of ThingsInternet of Things
Internet of Things
Dr Karthikeyan Periasamy
 
Padlet Creation
Padlet CreationPadlet Creation
Padlet Creation
Dr Karthikeyan Periasamy
 
Canvas LMS Creation
Canvas LMS CreationCanvas LMS Creation
Canvas LMS Creation
Dr Karthikeyan Periasamy
 

More from Dr Karthikeyan Periasamy (9)

Web tools - angular js
Web tools - angular jsWeb tools - angular js
Web tools - angular js
 
System types
System typesSystem types
System types
 
System thinking about system
System thinking   about systemSystem thinking   about system
System thinking about system
 
Android Database
Android DatabaseAndroid Database
Android Database
 
Android Introduction
Android IntroductionAndroid Introduction
Android Introduction
 
Arduino Programming
Arduino ProgrammingArduino Programming
Arduino Programming
 
Internet of Things
Internet of ThingsInternet of Things
Internet of Things
 
Padlet Creation
Padlet CreationPadlet Creation
Padlet Creation
 
Canvas LMS Creation
Canvas LMS CreationCanvas LMS Creation
Canvas LMS Creation
 

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
  • 5.
  • 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
  • 10.
  • 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
  • 20.
  • 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.
  • 22.
  • 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
  • 34.
  • 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