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
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
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
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
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
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
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â);
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