Download - Android
Mandus Elfving, IBS JavaSolutions, 2009
Android
What is Android?
• Operating system and platform for mobile devices
• Developed by Google and later by the Open Source Handset Alliance
• Mostly open sourced under the Apache and other open source licenses
Android features• Integrated browser based on the open source WebKit engine
• Optimized graphics powered by a custom 2D graphics library; 3D graphics based on the OpenGL ES 1.0 specification (hardware acceleration optional)
• SQLite for structured data storage
• Media support for common audio, video, and still image formats (MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, GIF)
• GSM Telephony (hardware dependent)
• Bluetooth, EDGE, 3G, and WiFi (hardware dependent)
• Camera, GPS, compass, and accelerometer (hardware dependent)
Architecture
Why is Android interesting to us?
Application development is done in Java!
Dalvik Virtual Machine
• Optimized for mobile devices
• Relies on the underlying OS for process separation, memory management and threading
• Designed to run multiple VM instances efficiently
• Executes its own type of byte code in files created from Java class files
Android vs. Java
• Based on Apache Harmony
• Supports most of the J2SE 5.0 library
• Applets, printing and other irrelevant stuff left out
• Includes third party libraries, e.g. bluetooth and JSON libraries
Applications
• Comes in .apk files which contain the application code and resources
• Run in their own Linux process
• Each process has its own VM
• Applications are assigned a unique user id that make sure that application data is private
Application building blocks
• Applications consist of components that are the entry points of an application
• Applications can use components from other applications
• Four types of components:
• Activities• Services• Broadcast receivers• Content providers
Application Building Blocks con't
Components declared in AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?><manifest . . . > <application . . . > <activity android:name="com.example.project.HelloWorldActivity" android:icon="@drawable/helloWorld.png" android:label="@string/helloWorldLabel" . . . > </activity> . . . </application></manifest>
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="se.jsolutions.android"> <application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name="HelloWorldActivity" 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>
Activities
• Interface for one of the activities that a user undertake in an application
• Applications are (usually) built from multiple activities
• The UI for an activity is built with Views
Services
• Used for long running background processes, e.g. media player
• Can run on its own in the background and/or be operated by an interface
• Run in the main thread of the application process
• Spawn thread to not block main thread
Broadcast receivers
• Components that react to system or application broadcasts
• System broadcasts for example when the battery level is low or the timezone changed
• Applications can initiate broadcasts that other applications can react to
Content providers
• Application data is by default private to the application
• Content providers make an applications private data available to other applications through a standardized API
• Accessed through a ContentResolver with an URI of the content provider to use, e.g. content://com.example.addressbook/contacts
• Android ships with standard content providers for common data types (audio, video, contacts, etc.)
Application navigation
• Components are activated by intents
• Intents are asynchronous messages
• Intents contain information relevant to the receiving component, e.g. action to take and data to act on
• Also contain information that the system use for finding the component that should handle it
Application navigation con't
• Components can be targeted explicitly or implicitly
• Intent filters define that a component can handle a specific implicit intents
• The system locates the best component to respond to an implicit intent
• Intent filters are defined in the manifest file
Application life cycle
• Tasks are groups of related activities arranged in a stack
• Tasks can be sent to the background or moved to the foreground
• Only one task and activity running at the same time
Application life cycle con't
• When system runs low on memory applications can be killed
• All applications are placed in an “importance hierarchy” to determine which application to kill next
• Importance is based on the components running in an application and their state
Application framework
• Consists of a set of services and systems to help in application development
• For example used to support localized applications and to build the graphical UI
• Used by core applications such as the SMS and Contacts applications
Views
Resource manager
• Provides access to non-code related resources such as localized strings or graphics
• Resources are compiled in to the application binary (resources reside in the res/ folder)
• Used by referencing symbols that are generated when the application is compiled (available in the R class), e.g. R.string.app_name or @string/app_name
Notification manager
• Allows the application to notify the user when something has happened in the background
• Different kinds:
• Icon in the status bar• LEDs on the device• Flashing backlight, playing a sound or vibrating
Security
• Applications are signed with a certificate
• Applications run in their own process with a unique user id
• Permissions restrict access to the data on the device
• Permissions granted by user on installation of application
• Permissions that application need and declaration of custom permissions is done in the application manifest file
Development environment
• Android SDK
• Command-line tools
• Eclipse with an Android plugin
• Execution/debugging in an emulator running the full OS and software stack
Phones
• First phone released October 2008 by T-mobile in the US and UK
• New phones during 2009 from the large phone companies
More information at:http://developer.android.com/