2. Agenda
• Android platform and ecosystem
• Android SDK and development tools
• Hello World
• building blocks of Android apps & the
manifest file
• activities, widgets, intents
4. Android platform
• Linux-based operating system
• open-source (http://source.android.com/)
• originally phone OS
• tablet support (since Honeycomb, Android
3.0)
• Google TV
5. History
• 2003, Android inc.
• 2005, acquired by Google
• Sep 2008, the first Android phone
• T-Mobile G1
• May 2010, Froyo (Android 2.2)
• Feb 2011, Honeycomb (Android 3.0)
6. History
• Oct 2011, Ice Cream Sandwich (Android
4.0)
• July 2012, Jelly Bean (Android 4.1)
• July 2013, Jelly Bean (Android 4.3)
• Oct 2013, KitKat (Android 4.4)
8. Android ecosystem
• thousands of devices
• the most popular mobile platform
• 1.5 million new devices activated every day
• September 3, 2013, 1 billion Android
devices have been activated
• most devices made by Samsung
9. Google Play
• app can be acquired by app stores
• Google Play, http://play.google.com
• other stores
• > 50 billion apps have been installed from
Google Play
• July 2013, 1 million apps
28. Android building blocks
• Activity
• Service
• Content provider
• Broadcast receiver
• AndroidManifest.xml
29. Activity
• screen with user interface
• the only visual component
• example - an email app
• list of emails
• details of an email
• email composition
30. Service
• has no UI
• long-running tasks
• examples
• music playback service
• download service
• sync service
31. Content Provider
• managers and shares application data
• data storage doesn’t matter (db, web,
filesystem)
• apps can query and modify data through
content provider
• r/w permissions can be defined
• examples - all system dbs (SMS, contacts, ...)
32. Broadcast Receiver
• responds to broadcasts
• broadcasts are system wide
• can be registered statically or dynamically
• system or custom messages
• examples - incoming SMS, incoming call,
screen turned off, low baterry, removed SD
card, BT device available, ...
33. AndroidManifest.xml
• defines what parts the app have
• defines which endpoints are exposed
• minimum/maximum API level
• permissions
• declare hardware and software features
• require configuration
34. Intent
• asynchronous message
• binds components together (all except
Content Provider)
• starting activities
• starting services and binding to services
• sending broadcasts
35. Activity
• a subclass of android.app.Activity
• app usually has many activities
• activities managed in activity stack
• newly started activity is placed on the top
of the stack
36. Activity Lifecycle
• activity can be in different states during its
lifecycle
• foreground, visible, stopped, killed
• when activity state changes a system
callback is called
37. Activity callbacks
• onCreate() - activity created
• onStart() - activity visible for the user
• onResume() - activity gains user focus
• onPause() - system resuming another
activity
• onStop() - activity becoming invisible to
the user
38. Activity callbacks
• onDestroy() - before activity is
destroyed
• onRestart() - called if activity was
previously stopped, called prior to onStart()
39.
40.
41. Configuration changes
• when configuration changes, activities are
destroyed and recreated
• default behaviour, can be changed
• properly handle config changes
•
onSaveInstanceState(Bundle)
42. Intent & Activity
• starting activity explicitly
•
new Intent(context, MyActivity.class)!
•
new Intent(Intent.ACTION_VIEW, Uri.parse(“http://
developer.android.com”))!
• starting activity implicitly
• starting activity for result
43. User Interface
• defined by a hierarchy of views
• layouts = containers
•
LinearLayout, RelativeLayout, FrameLayout, ...
45. User Interface
• list widgets
• subclasses of AdapterView
• display a list of items
• use adapter to bind list do data
•
ListView, GridView, Spinner, ...
51. Resources
• resources can be created in several
versions
• the best version is selected according to
current device configuration in runtime
• resource units
• dp - density-independent pixel
• sp - scale-independent pixel (for fonts)
57. Android version
fragmentation
• build target
• API level the app is compiled against
• AndroidManifest.xml
•
<uses-sdk android:minSdkVersion="8"
android:targetSdkVersion="16" />
60. Fragments
• a piece of application UI
• introduced to support more flexible UI
• phones and tablets together in one app
• fragment != activity
• fragments are used within activities
62. Threads
• main thread = UI thread
• do not ever block the UI thread!!!
• use worker threads for time consuming
operations
• UI toolkit not thread safe - never
manipulate UI from a worker thread
63. Menu
• menu resource
• Android < 3.0 the whole menu hidden
under menu button
• ActionBar since Android 3.0
• items can be displayed in the action bar
64. Menu
• behaviour for items that don’t fit in the
action bar
• hidden under menu button (if the device
has one)
• system overflow icon in the action bar
66. Dialogs
• standard dialogs
• custom dialogs
• activity with dialog style
• since fragments used via DialogFragment
67. Dialogs
• might be tedious to create
• difficult to style
• StyledDialogs
•
https://github.com/inmite/android-styled-dialogs
• the library makes styling and using dialogs
a piece of cake
68. Toast
• simple non-modal information
• displayed for a short period of time
• doesn’t have user focus
69. Notifications
• a message that can be displayed to the user
outside your normal UI
• displayed in notification area
70. Notifications
• user can open notification drawer to see
the details
• app can define UI and click action
•
NotificationCompat.Builder