SlideShare a Scribd company logo
ANDROIDBeginners Workshop
Nitin R Patel
Purvik N Rana
Outline
 Era of Mobile OS
 Android
• What it is..!
• Software stack
• Components
• App fundamentals
 Development Environments
• Tools/Setups
 Application Structure
 Layouts and View
 Activity
 Fragments
 Services
ERA OF MOBILE OS
 Symbian
• low-end phones
 Android
• Sep 20th, 2008 (Astro)
 Apple iOS
• June 29th, 2007
 BlackBerry
• property of Research in Motion (RIM) found in1999
 Windows
• Started by Nokia to take his reputation back to forth
 BADA
• owns by Samsung
ANDROID OS
What it is..!!
 Free – open source OS (platform for app creation)
 Linux kernel based OS
 Developed by Google and later the Open Handset Alliance (OHA)
 Allow to write/manage code in the Java
 Core and third party app are equal
 Easy and fast app development
 Era of Android starts since 5 November 2007
OHA
 Open Handset Alliance
 Group of technology and mobile companies
 First free provided mobile platform is – Android
 Providing richer experience (with open standards)  main Goal
 Handset manufactures are free to pay licencing fees to load
Android
Version History
Version Codename API Distribution
4.0.3 -
4.0.4
Ice Cream
Sandwich
15 3.7%
4.2.x
Jelly Bean
17 15.2%
4.3 18 4.5%
4.4 KitKat 19 39.2%
5.0
Lollipop
21 15.9%
5.1 22 5.1%
Native Android Applications
 Home Screen
 Music Player, Picture Gallery
 SMS, E-mail
 Camera Apps
 Full PIM (Calendar, Contacts)
 Web Browsers
 Play Store
 Sensors
 Google Maps
 Google Talk
 Google Mail Client
 YouTube
 Data Stores
 Much more . . .
Android Software Stack
• Contain all the Low level drivers for various hardware components of
Android
• Relaying on Linux Kernel for core system services like
• Memory and process management
• Network stack
• Driver model
• Security
• Provide Abstraction between hardware and rest of the software stack
Linux Kernel
• Set of Core libraries – enable developers to write Android Apps using
Java Programming
• DVM – Dalvik Virtual Machine
Android Runtime
Dalvik Virtual Machine
 Provides environment to let us execute Android application
 Each Android application runs in its own process
• Have it’s own instance of the Dalvik VM
 Dalvik has been written such that a device can run multiple VMs
efficiently.
 Register-based virtual machine
• Executing the Dalvik Executable (.dex) format
• .dex format is optimized for minimal memory footprint.
 Compilation
• Relying on the Linux Kernel for: Threading & other Low-level
memory management
 Exposed to developers through the Android application framework
 Including a set of C/C++ libraries used by components of the Android system
 Code for main features
• SQLite library- data storage
• WebKit library – functions for web browsing and much more..
Libraries
 Expose various capabilities of Android – developers use them in their
Apps
 Enabling and simplifying the reuse of components
• Developers have full access to the same framework APIs used by
the core applications
• Users are allowed to replace components
Application Framework
 Features
 Apps that download and install from Android Market
 Android provides a set of core applications:
• Email Client
• SMS Program
• Calendar
• Maps
• Browser
• Contacts etc…
Applications
Android Components
 Activities
• Single UI that handle the user interaction, app contains one or more activities
 Services
• handle background processing for applications, doesn‟t have UI
 Broadcast Receivers
• handle communication between Android OS and applications
 Content Providers
• handle data and database management issues
 Views
• UI elements like Buttons, Textviews and many more…
Android Application Fundamental
 Individual app lives in its own world
• Each application has its own process
• Identify with unique Linux user ID
• File alteration only permitted – ID and apps (through permission)
 Applications in between can – process elements of each other
DEVELOPMENT ENVIRONMENT
Eclipse – Android Studio
System requirements
 OS
• Xp (32) , Vista (32 - 64), 7 (32 - 64)
• Mac OS (10.5.8 or later)
• Linux
 Eclipse IDE (3.6.2 or later)
 Android SDK
 ADT Plug In
 JDK 6 (or later)
Continue . .
 Remember to get download of right version of java
 Unpack ZIP of SDK at appropriate location
 Install additional version of Android as well as other packages
 Configure Android Development Environment on Eclipse
• Add New Software to Eclipse
• ADT Plug In configuration
ADT integration in Eclipse
Android Workshop_1
SDK Manager
Android Virtual Device
DDMS Perspective
Debug..
Android Studio
Studio interface
First Hello World Example (Demo)
ANDROID APPLICATION STRUCTURE
 Codes & Resources resides in Different Folders
 Can be added as needed
• src : all source codes
• gen : java files generated by ADT
• assets : store raw assests files
• bin : output directory
• res : resources of our application
• res/drawable : image/image-descriptor files
• res/layouts : layouts of application
• res/menus : application menus
• res/values : other resources of application like
• Strings, Styles, Colors and so on… (xml based)
Studio file structure
 Benefits
• Good to keep code away from all other things
• Easy to maintain – update – manage
• Support different devices and localization
• Resource selection dynamically at runtime
 System resources defined under System.R
Strings.xml
Colors.xml
 Efficient to group all colors in one separate file like strings the
same way…
Androidmenifest.xml
 Application descriptor file
 Properties like..
• Activities
• Content Providers
• Services
• Intent Receivers
• Permissions
• Version Number
• And much more . . .
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.svit.helloworld"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="19"
android:targetSdkVersion="21" />
<application android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity" android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Different language and hardware
 Dynamic resource collection mechanism
• Done with dynamic directory structure
• Specific language, location, hardware
• Alternatives described with – mark
 Like.
• res/layout/main.xml
• res/layout-land/main.xml
• res/values-fi/strings.xml
• res/values-en/strings/xml
Screen orientation support
 Portrait and Landscape mode can be done easily by resources
• Portrait – automatically
• Landscape – specified in layout-land
• Phone switches layout automatically by when orientation changes
BREAK
LAYOUTS AND VIEWS
 Android Application UI is built using Views and Viewgroups
 Different “Widgets” like Button, Textview, which are the UI
objects are the subclass of the class “View”
 “Layouts‟‟ are the subclass of Viewgroup
 Different types of Layouts are available in this class
 Various Layouts
• Arrange the views in Single Row or Single Column
Linear Layout
• Group views into rows and column
• <TableRow> - design a Row in the Table
Table Layout
• Enables you to set child position relative to each other
Relative Layout
• A blank space on the screen which can later be filled with a
single object
Frame Layout
Defining Layouts with xml
 Most common way is to use XML for declaring Layout
 Each element of XML is ether a View or a Viewgroup
 The Name of the XML element is like the java class that
represents like <TextView> element creates a Textview in the UI
 Android attach the view hierarchy tree to the screen
 Activity call the setContentView() method and pass the reference
to the root node object
 Then draw() method of the view is called to draw the widget on
screen
 Linear Layout Example
 Relative Layout Example
 Relative Layout Example
 Relative Layout Example
 Relative Layout Example
Common Input controls
 Input controls are the interactive components of
the application‟s User Interface
 Android provides wide variety of controls like
Buttons, Text fields, seekbars, checkboxes,
spinners, pickers and so on….
 Use drag and drop the controls from palette to
set controls to layout or edit in XML file
directory
Handling UI Events
 Many ways to intercept the events from a user‟s interaction
depends on the SDK version
 The approach is to capture the events from the specific view
object that the user interacts with
 Use different EventListeners with code or in XML
• onClick, onLongClick, onFocusChange, …….
Handling UI Events
ACTIVITY
basic
 App Component (UI) – user interact to do something
 One app – multiple activities
• Main activity – launch time presented activity
• Other – specified to particular tasks
 Each activity can start another activity
 Subclass of Activity class
 callBack methods – system calls different states of app activity
 Activities are set in the stacks – root activity (begin the Task of
Application)
 Three main states: running, paused, stopped
• Pasued/stoppped : system can drop it from
memory
• UI, data sources and EventHandlers are
bind in onCreate()
• After onResume() : activity visible to user
• onPause() : save critical data at app data
store
 android:name - specify class name of the Activity
 Other attributes – specify additional information (label, icon,
theme..)
 Intent filter – make your activity available to system or other
applications
INTENTS
basics
 Most important and unique concepts
 Like „message‟to someone
 Can be used to
• Broadcast/Transfer data between application and app components
• Start Activities and Services
• Broadcast that event/action has occurred
 Intent Object  like bundle of information
 Contains
• Component : explicit name of component class to use for intent
• Action : action to be perform
• Data : URI of data to be acted on
• Category : string that indicate kind of a component that should handle
the intent
• Type : indicate Type of intent data
• Extras : key-value pairs of information
• Flags : instruct how to launch activity and how to treat it
Intent object actions
Intent object data
 ACTION_VIEW content://contacts/people/1
 ACTOIN_DIAL content://contacts/people/1
 ACTION_VIEW tel:123
 ACTION_DIAL tel:123
 ACTION_EDIT content://contacts/people/1
Intent object category
 Any no of category can be included for intent to categorized
Intent object extras
 Bundle of additional information
 Provide extended information to the component
Intent resolution
 Two groups
• Explicit : used for application-internal messages(b/w activities)
• Delivered to an instance of designated target class
• startActivity(intent)
• Starts new Activity (Data can be passed with intent)
• Parent does not notify when child activity completes
• startActivityForResult(intent, REQUEST_CODE)
• same but parent get notify when child activity completes by OnActivityCompletes()
• Implicit : used to activate components in other applications
• Resolved by intent filters by object‟s (Action – Data - Category)
• System must find best component to handle intent
Intent filter
 Explicit – always deliver to target class
 Activities, Services and Broadcast receivers can have one or more
intent filters
 Filter describes the capability of a component
 Defined in the manifest file
Passing data between activities
 Intent can have addtional data  extras
 Key/value pair
 Send data:
• intent.putExtra(“info”,value);
 Get data:
• Bundle extra = getIntent().getExtras();
• int var = extra.getInt(“info”);
Receiving result from an activity
 Custom Intents
• Customize name in the manifest to receive intent
 Broadcast Intents
• No activity needed
• Listen broadcast intents
• Register in manifest file as Receiver
• Intent-filter used to match with listened intent actions
Custom intent
Broadcast intents
FRAGMENTS
Fragment Basics
 Fragment represents a behaviour or a portion of user interface in
an Activity
 To build a multi-Pane UI, multiple fragments are combined in a
single activity
 Fragment must be embedded in an activity
 Fragment has its own lifecycle
 It supports more dynamic and flexible UI designs on large screens
 Example of Typical fragment:
• For Tablet: - list in left & content on right
• For Handset: - List & content on different Activity
SERVICES
basic
 Components runs in background (without UI)
 not a separate process or thread
 Can be stand alone process or part of an application
 Started, stopped, controlled by other application cpmponents
 Started services have higher priority than inactive or invisible activities
 Supports
• local services (not accessible outside of application)
• remote services (accessible outside of application)
Service creation
 Create class that extends Service class
 Override needed methods
• onCreate() : Launched on main application thread
• onStartCommand(Intent, int, int) : Create and run new thread
• onBind() : bind Activities to Service
• onDestroy() : do all clean up (stop threads,..)
Service lifcycle
 Context.startService()
• onCreate() : create a Service
• onStart() : start it
• onStartCommand()
• Context.stopService()/stopSelf() : Stops it
 Client.bindService()
• Create if it is not already running
• Doesn‟t call onStartCommand()
• onBind() : client will receive Ibinder object from
Service itself
• Remain running as long as connection is established
• Allows client to call back to Service
Android Workshop_1
Android Workshop_1
Android Workshop_1
Day 1 ends here

More Related Content

PDF
Andriod_Intro
ODP
PPTX
Android Application Fundamentals
PPTX
Introduction to android basics
PPT
Android General information
PDF
01 03 - introduction to android
PPT
Android application development for TresmaxAsia
PPT
My androidpresentation
Andriod_Intro
Android Application Fundamentals
Introduction to android basics
Android General information
01 03 - introduction to android
Android application development for TresmaxAsia
My androidpresentation

What's hot (20)

PPTX
Android workshop
PPTX
Android architecture
PPTX
Android- Introduction for Beginners
PPT
Introduction to android
PDF
Android Presentation
PPT
Android primer
PPTX
Android architecture
PPT
Android software stack
PPTX
Anatomy of android aplication
PPTX
Android the new Mobile Technoogy
PDF
Android Architecture
PPT
Android Seminar
PPT
Android Anatomy
PPTX
Android 1-intro n architecture
PPTX
Android Operating System Architecture
PDF
Introduction to android
PPT
Android For Java Developers
PPTX
android
PPT
Andriod
PPTX
Session 2 beccse
Android workshop
Android architecture
Android- Introduction for Beginners
Introduction to android
Android Presentation
Android primer
Android architecture
Android software stack
Anatomy of android aplication
Android the new Mobile Technoogy
Android Architecture
Android Seminar
Android Anatomy
Android 1-intro n architecture
Android Operating System Architecture
Introduction to android
Android For Java Developers
android
Andriod
Session 2 beccse
Ad

Similar to Android Workshop_1 (20)

PPTX
Introduction to Android (before 2015)
PDF
Android Development
PPTX
Introduction to Android and Android Studio
PPT
Android architecture
PPT
Unit I- ANDROID OVERVIEW.ppt
PDF
Android fundamentals and tutorial for beginners
PPT
Introduction to Android Development
PPTX
Android Penetration Testing - Day 1
PPTX
Introduction to Android Development.pptx
PPSX
Android OS and its Features
PPTX
Android Technology
PPTX
Intro to android (gdays)
PPT
introductiontoandroiddevelopment (2).ppt
PPTX
Overview of Adroid Architecture.pptx
PDF
Learn Android at edureka!
PDF
Android Deep Dive
ODP
Intro To Android App Development
PDF
Android
PPT
Introduction to android sessions new
PDF
Matteo Gazzurelli - Introduction to Android Development - Have a break edition
Introduction to Android (before 2015)
Android Development
Introduction to Android and Android Studio
Android architecture
Unit I- ANDROID OVERVIEW.ppt
Android fundamentals and tutorial for beginners
Introduction to Android Development
Android Penetration Testing - Day 1
Introduction to Android Development.pptx
Android OS and its Features
Android Technology
Intro to android (gdays)
introductiontoandroiddevelopment (2).ppt
Overview of Adroid Architecture.pptx
Learn Android at edureka!
Android Deep Dive
Intro To Android App Development
Android
Introduction to android sessions new
Matteo Gazzurelli - Introduction to Android Development - Have a break edition
Ad

More from Purvik Rana (8)

PDF
Software Quality Assurance - Software Engineering
PDF
Software Designing - Software Engineering
PDF
Agile Methodology - Software Engineering
PDF
Software Engineering - Basics
PDF
OOPs Concepts - Android Programming
PDF
Sql queries - Basics
PDF
Apple bonjour
PDF
File system in iOS
Software Quality Assurance - Software Engineering
Software Designing - Software Engineering
Agile Methodology - Software Engineering
Software Engineering - Basics
OOPs Concepts - Android Programming
Sql queries - Basics
Apple bonjour
File system in iOS

Recently uploaded (20)

PDF
VCE English Exam - Section C Student Revision Booklet
PDF
TR - Agricultural Crops Production NC III.pdf
PPTX
Institutional Correction lecture only . . .
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
Classroom Observation Tools for Teachers
PDF
Insiders guide to clinical Medicine.pdf
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
RMMM.pdf make it easy to upload and study
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
Cell Structure & Organelles in detailed.
PDF
01-Introduction-to-Information-Management.pdf
VCE English Exam - Section C Student Revision Booklet
TR - Agricultural Crops Production NC III.pdf
Institutional Correction lecture only . . .
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Classroom Observation Tools for Teachers
Insiders guide to clinical Medicine.pdf
Microbial diseases, their pathogenesis and prophylaxis
RMMM.pdf make it easy to upload and study
Microbial disease of the cardiovascular and lymphatic systems
Week 4 Term 3 Study Techniques revisited.pptx
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
O5-L3 Freight Transport Ops (International) V1.pdf
Cell Structure & Organelles in detailed.
01-Introduction-to-Information-Management.pdf

Android Workshop_1

  • 1. ANDROIDBeginners Workshop Nitin R Patel Purvik N Rana
  • 2. Outline  Era of Mobile OS  Android • What it is..! • Software stack • Components • App fundamentals  Development Environments • Tools/Setups  Application Structure  Layouts and View  Activity  Fragments  Services
  • 4.  Symbian • low-end phones  Android • Sep 20th, 2008 (Astro)  Apple iOS • June 29th, 2007  BlackBerry • property of Research in Motion (RIM) found in1999  Windows • Started by Nokia to take his reputation back to forth  BADA • owns by Samsung
  • 6. What it is..!!  Free – open source OS (platform for app creation)  Linux kernel based OS  Developed by Google and later the Open Handset Alliance (OHA)  Allow to write/manage code in the Java  Core and third party app are equal  Easy and fast app development  Era of Android starts since 5 November 2007
  • 7. OHA  Open Handset Alliance  Group of technology and mobile companies  First free provided mobile platform is – Android  Providing richer experience (with open standards)  main Goal  Handset manufactures are free to pay licencing fees to load Android
  • 9. Version Codename API Distribution 4.0.3 - 4.0.4 Ice Cream Sandwich 15 3.7% 4.2.x Jelly Bean 17 15.2% 4.3 18 4.5% 4.4 KitKat 19 39.2% 5.0 Lollipop 21 15.9% 5.1 22 5.1%
  • 10. Native Android Applications  Home Screen  Music Player, Picture Gallery  SMS, E-mail  Camera Apps  Full PIM (Calendar, Contacts)  Web Browsers  Play Store  Sensors  Google Maps  Google Talk  Google Mail Client  YouTube  Data Stores  Much more . . .
  • 12. • Contain all the Low level drivers for various hardware components of Android • Relaying on Linux Kernel for core system services like • Memory and process management • Network stack • Driver model • Security • Provide Abstraction between hardware and rest of the software stack Linux Kernel
  • 13. • Set of Core libraries – enable developers to write Android Apps using Java Programming • DVM – Dalvik Virtual Machine Android Runtime
  • 14. Dalvik Virtual Machine  Provides environment to let us execute Android application  Each Android application runs in its own process • Have it’s own instance of the Dalvik VM  Dalvik has been written such that a device can run multiple VMs efficiently.  Register-based virtual machine • Executing the Dalvik Executable (.dex) format • .dex format is optimized for minimal memory footprint.  Compilation • Relying on the Linux Kernel for: Threading & other Low-level memory management
  • 15.  Exposed to developers through the Android application framework  Including a set of C/C++ libraries used by components of the Android system  Code for main features • SQLite library- data storage • WebKit library – functions for web browsing and much more.. Libraries
  • 16.  Expose various capabilities of Android – developers use them in their Apps  Enabling and simplifying the reuse of components • Developers have full access to the same framework APIs used by the core applications • Users are allowed to replace components Application Framework
  • 18.  Apps that download and install from Android Market  Android provides a set of core applications: • Email Client • SMS Program • Calendar • Maps • Browser • Contacts etc… Applications
  • 19. Android Components  Activities • Single UI that handle the user interaction, app contains one or more activities  Services • handle background processing for applications, doesn‟t have UI  Broadcast Receivers • handle communication between Android OS and applications  Content Providers • handle data and database management issues  Views • UI elements like Buttons, Textviews and many more…
  • 20. Android Application Fundamental  Individual app lives in its own world • Each application has its own process • Identify with unique Linux user ID • File alteration only permitted – ID and apps (through permission)  Applications in between can – process elements of each other
  • 22. System requirements  OS • Xp (32) , Vista (32 - 64), 7 (32 - 64) • Mac OS (10.5.8 or later) • Linux  Eclipse IDE (3.6.2 or later)  Android SDK  ADT Plug In  JDK 6 (or later)
  • 23. Continue . .  Remember to get download of right version of java  Unpack ZIP of SDK at appropriate location  Install additional version of Android as well as other packages  Configure Android Development Environment on Eclipse • Add New Software to Eclipse • ADT Plug In configuration
  • 32. First Hello World Example (Demo)
  • 34.  Codes & Resources resides in Different Folders  Can be added as needed • src : all source codes • gen : java files generated by ADT • assets : store raw assests files • bin : output directory • res : resources of our application • res/drawable : image/image-descriptor files • res/layouts : layouts of application • res/menus : application menus • res/values : other resources of application like • Strings, Styles, Colors and so on… (xml based)
  • 36.  Benefits • Good to keep code away from all other things • Easy to maintain – update – manage • Support different devices and localization • Resource selection dynamically at runtime  System resources defined under System.R
  • 38. Colors.xml  Efficient to group all colors in one separate file like strings the same way…
  • 39. Androidmenifest.xml  Application descriptor file  Properties like.. • Activities • Content Providers • Services • Intent Receivers • Permissions • Version Number • And much more . . . <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.svit.helloworld" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="21" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name=".MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
  • 40. Different language and hardware  Dynamic resource collection mechanism • Done with dynamic directory structure • Specific language, location, hardware • Alternatives described with – mark  Like. • res/layout/main.xml • res/layout-land/main.xml • res/values-fi/strings.xml • res/values-en/strings/xml
  • 41. Screen orientation support  Portrait and Landscape mode can be done easily by resources • Portrait – automatically • Landscape – specified in layout-land • Phone switches layout automatically by when orientation changes
  • 42. BREAK
  • 44.  Android Application UI is built using Views and Viewgroups  Different “Widgets” like Button, Textview, which are the UI objects are the subclass of the class “View”  “Layouts‟‟ are the subclass of Viewgroup  Different types of Layouts are available in this class
  • 45.  Various Layouts • Arrange the views in Single Row or Single Column Linear Layout • Group views into rows and column • <TableRow> - design a Row in the Table Table Layout • Enables you to set child position relative to each other Relative Layout • A blank space on the screen which can later be filled with a single object Frame Layout
  • 46. Defining Layouts with xml  Most common way is to use XML for declaring Layout  Each element of XML is ether a View or a Viewgroup  The Name of the XML element is like the java class that represents like <TextView> element creates a Textview in the UI  Android attach the view hierarchy tree to the screen  Activity call the setContentView() method and pass the reference to the root node object  Then draw() method of the view is called to draw the widget on screen
  • 47.  Linear Layout Example
  • 52. Common Input controls  Input controls are the interactive components of the application‟s User Interface  Android provides wide variety of controls like Buttons, Text fields, seekbars, checkboxes, spinners, pickers and so on….  Use drag and drop the controls from palette to set controls to layout or edit in XML file directory
  • 53. Handling UI Events  Many ways to intercept the events from a user‟s interaction depends on the SDK version  The approach is to capture the events from the specific view object that the user interacts with  Use different EventListeners with code or in XML • onClick, onLongClick, onFocusChange, …….
  • 56. basic  App Component (UI) – user interact to do something  One app – multiple activities • Main activity – launch time presented activity • Other – specified to particular tasks  Each activity can start another activity  Subclass of Activity class  callBack methods – system calls different states of app activity  Activities are set in the stacks – root activity (begin the Task of Application)
  • 57.  Three main states: running, paused, stopped • Pasued/stoppped : system can drop it from memory • UI, data sources and EventHandlers are bind in onCreate() • After onResume() : activity visible to user • onPause() : save critical data at app data store
  • 58.  android:name - specify class name of the Activity  Other attributes – specify additional information (label, icon, theme..)  Intent filter – make your activity available to system or other applications
  • 60. basics  Most important and unique concepts  Like „message‟to someone  Can be used to • Broadcast/Transfer data between application and app components • Start Activities and Services • Broadcast that event/action has occurred
  • 61.  Intent Object  like bundle of information  Contains • Component : explicit name of component class to use for intent • Action : action to be perform • Data : URI of data to be acted on • Category : string that indicate kind of a component that should handle the intent • Type : indicate Type of intent data • Extras : key-value pairs of information • Flags : instruct how to launch activity and how to treat it
  • 63. Intent object data  ACTION_VIEW content://contacts/people/1  ACTOIN_DIAL content://contacts/people/1  ACTION_VIEW tel:123  ACTION_DIAL tel:123  ACTION_EDIT content://contacts/people/1
  • 64. Intent object category  Any no of category can be included for intent to categorized
  • 65. Intent object extras  Bundle of additional information  Provide extended information to the component
  • 66. Intent resolution  Two groups • Explicit : used for application-internal messages(b/w activities) • Delivered to an instance of designated target class • startActivity(intent) • Starts new Activity (Data can be passed with intent) • Parent does not notify when child activity completes • startActivityForResult(intent, REQUEST_CODE) • same but parent get notify when child activity completes by OnActivityCompletes() • Implicit : used to activate components in other applications • Resolved by intent filters by object‟s (Action – Data - Category) • System must find best component to handle intent
  • 67. Intent filter  Explicit – always deliver to target class  Activities, Services and Broadcast receivers can have one or more intent filters  Filter describes the capability of a component  Defined in the manifest file
  • 68. Passing data between activities  Intent can have addtional data  extras  Key/value pair  Send data: • intent.putExtra(“info”,value);  Get data: • Bundle extra = getIntent().getExtras(); • int var = extra.getInt(“info”);
  • 69. Receiving result from an activity
  • 70.  Custom Intents • Customize name in the manifest to receive intent  Broadcast Intents • No activity needed • Listen broadcast intents • Register in manifest file as Receiver • Intent-filter used to match with listened intent actions
  • 74. Fragment Basics  Fragment represents a behaviour or a portion of user interface in an Activity  To build a multi-Pane UI, multiple fragments are combined in a single activity  Fragment must be embedded in an activity  Fragment has its own lifecycle  It supports more dynamic and flexible UI designs on large screens
  • 75.  Example of Typical fragment: • For Tablet: - list in left & content on right • For Handset: - List & content on different Activity
  • 77. basic  Components runs in background (without UI)  not a separate process or thread  Can be stand alone process or part of an application  Started, stopped, controlled by other application cpmponents  Started services have higher priority than inactive or invisible activities  Supports • local services (not accessible outside of application) • remote services (accessible outside of application)
  • 78. Service creation  Create class that extends Service class  Override needed methods • onCreate() : Launched on main application thread • onStartCommand(Intent, int, int) : Create and run new thread • onBind() : bind Activities to Service • onDestroy() : do all clean up (stop threads,..)
  • 79. Service lifcycle  Context.startService() • onCreate() : create a Service • onStart() : start it • onStartCommand() • Context.stopService()/stopSelf() : Stops it  Client.bindService() • Create if it is not already running • Doesn‟t call onStartCommand() • onBind() : client will receive Ibinder object from Service itself • Remain running as long as connection is established • Allows client to call back to Service
  • 83. Day 1 ends here