Professional Documents
Culture Documents
Android Architecture
some details
brief introduction
Component diagram of the Android operating system Today, we are focusing on the application part
Core Libraries
A set of C/C++ libraries, which are built on Linux Kernel System C Library
Standard C library, tuned for embedded Linux Playback and recording of audio and video Display subsystem management Composites 2D/3D graphic layers Embeddable web browser 2D graphic engine, hardware 3D Acceleration Relational database engine
Media Libraries
Surface Manager
LibWebCore
SGL/3D Libraries
SQLite
Application Framework
Use device hardware, access location information, set alarms, add notifications to the status bar, and more Views
View is a area for drawing and event handling e.g. buttons, lists, grids, and even web browser Access or share data among applications e.g. contacts, and MediaStore Access non-code resources e.g. localized strings, images, and layout files Display alerts in the status bar Manages lifecycles of applications Provides a common navigation
Content Providers
Resource Manager
Notification Manager
Activity Manager
Applications
An app listens phone state changes via Telephony Manager An app exploits an ImageView object from View System A new activity has Activity Manager change states of others
Application Components
Activities
Activity Stack
Start from users activation End when it is closed by user Similar to a full window in MS Windows
Application Components
Activities Services
Run in background to perform longrunning operations Once started, last until it is terminated e.g. messenger service, music player
Running Services
Application Components
read
Schedule Provider
add
Manages shared set of application data Other applications can read and even modify data Once registered, last until it is terminated e.g. Contacts, Settings, Calendar provider
Registered Contents Providers
Broadcast Receivers
Application Components
broadcast
Phone call
broadcast
Alarm
Alarm receiver
Start when the event is received End after handling the event e.g. alarm, phone call, SMS notifier
Application Components
Activities
A single screen with a user interface Runs in background to perform long-running operations Manages shared set of application data Responds to broad-cast events
Services
Contents Providers
Broadcast Receivers
You don t have to write all these components Required components depend on your app s purpose
A music player requires activities and services A dictionary consists of activities and content providers A SMS manager needs activities and broadcast receivers
10
Suppose you are going to make SNS app, and this app requires updating photos from camera Which one of the following choices is better than others?
Writing code for taking pictures Incorporate another code Activate the existing well-made camera app and get result from it
Intent
I d like to run an app can get music Run the selected app as the description of this intent
11
Summary
Android applications are built on Android application framework with fruitful functionalities Android applications consist of four components: Activity, Contents Provider, Service, and Broadcast Receiver Android applications can activate or communicate with another application s component
12
Installation list
For building java source code Contains Core SDK Tools and Components For convenience in development Eclipse plug-in offered by android Helps Eclipse to create and debug applications
14
Android SDK
Install JDK
http://www.oracle.com/technetwork/java/javase/downloads/index.html
Control Panel > System > Advanced, Select Environment Variables Set environment variable PATH to your JDK install path
15
http://developer.android.com/sdk/index.html If installer failed to find JDK under 64bit Windows, then click Back and Next button again
16
http://www.eclipse.org/downloads/
Unzip the downloaded file Execute eclipse.exe to open IDE Set workspace to your working directory
17
Start eclipse Select Help > Install New Software Click Add and Add Repository with the following URL
https://dl-ssl.google.com/android/eclipse/
18
Open the menu Windows>Preferences Set SDK Location to your Android SDK path Apply to list available android targets
Your Android SDK path
19
acts like a real device except for a few limitations Open Window>Android SDK and AVD Manager Select device target and decide the size of SD Card Create AVD and try starting the device
20
Hello Android!
File>New>Project, Select Android Project Select build target Write down properties
21
22
Src folder
Java files to be implemented Auto-generated java files Any files you want to ship with Resources such as images, layouts and fonts Essential information about the application
gen folder
assets folder
res folder
AndroidManifest.xml file
23
Modify the value of field hello to Hello Android There s the other field app_name , the title 24
To see the current layout, open main.xml in layout folder Moreover, double-clicking on the text leads to open a text editor for layout
25
Layout object
A container of other layout and widget object Arrange containing widgets in an order e.g. LinearLayout, RelativeLayout, TabLayout, UI element displayed on screen Corresponds to the event such as clicking, mouse over, e.g. TextView, Button, DatePicker, Gallery, WebView,
Widget object
Layouts
Widgets 26
Just setting up the layout is not enough to make an android application Instead of a boring app, to make more interactive app, let s place a button on screen
Open main.xml in res>layout folder Drag Button to the screen Double-click the button to open the text layout editor
27
To have the button listen a event, the source code Main.java should be rewritten
import necessaries
28
Summary
To develop android applications, it is required to install JDK, Android SDK, Eclipse IDE, Eclipse ADT plug-in To test android applications, usually Android Virtual Device(AVD) is enough Android offers a variety of UI elements and containers for layout All the Android UI elements can handle events such as click and touch for user interaction
29
Debugging
Most software developers suffers from the fault or malfunction of their program Debugging is the process finding errors or bugs and making the program run in the desired way Debugger is a program used to test and debug other programs, nowadays debuggers become important to save time and effort for software development
31
Android Debug Bridge(ADB) and Dalvik Debug Monitor Server(DDMS) are debugging tools
Shipped with Android SDK Let you manage the state of Android device Provides many debugging capabilities
Examining memory, methods, and log Emulating phone operations and location Installing an application, and copying files Printing log and dump data Issuing a shell command in devices
e.g. Running an app in Eclipse consists of two ADB commands: install and start 32
Debugging in Android
Call Stack
Variables
Thanks to ADT and debugger tools in SDK Setting breakpoints Step-by-step execution Watching variables Check the current call stack
Source View
33
Android LogCat dumps a log collected ADT provides LogCat window for Eclipse
34
Similar to printf or std::cout in console program Log.v, Log.d, Log.i, Log.w, Log.e Verbose, debug, information, warning, error
35
File Explorer
Emulator Control
Changes telephone state Spoofs calls or SMS Sets the location manually
Devices
List available devices Debug and stop a process Capture the screen of a device
Displays the current placement of widgets Shows hierarchical relationships between layouts
36
Summary
Debugging is important to save time and effort ADB and DDMS are debugger tools shipped with Android SDK Debugging and Logging can be easily performed on Eclipse via Eclipse ADT Another tools are also available for debugging and testing
37