Sei sulla pagina 1di 37

Introduction to Android Application

Kyuseok Shim EECS, SNU

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


Application Framework provides services and systems




Use device hardware, access location information, set alarms, add notifications to the status bar, and more Views
 

Application framework is composed of




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


Built on application framework


  

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

 

Written in Java programming Language Core applications shipped with Android




, get, listen, request,

don t care what happens actually

Application Components


Application building blocks




Activities


A single screen with a user interface


 

Activity Stack

Enable to draw and handle events Most frequently used, undoubtedly

  

Start from users activation End when it is closed by user Similar to a full window in MS Windows

  

Services Contents Providers Broadcast Receivers


6

Application Components


Application building blocks


 

Activities Services


Check if there s a new message

 

Run in background to perform longrunning operations Once started, last until it is terminated e.g. messenger service, music player

Monitoring phone usage


Playing music in background

 

Contents Providers Broadcast Receivers

Running Services

Application Components


Application building blocks


  

read

Activities Services Contents Providers


 

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


Application building blocks


   

Activities Services Contents Providers Broadcast Receivers





broadcast

Phone call

Phone call receiver

start activity for phone call

broadcast

start activity for alarm

Alarm

Alarm receiver

Responds to broad-cast events


low battery, SMS received,

  

Start when the event is received End after handling the event e.g. alarm, phone call, SMS notifier

Your app s Alarm Receiver

anything you want to do about this alarm

Application Components


Application building blocks




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

Communications Between Application Components




Android application can start another application s component




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 is a message object


 

Description of operation to be performed Mostly used for launching another application




e.g. Is there anyone can play a music?

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

Android Application Development: Get Started


Kyuseok Shim EECS, SNU

Installation list


Java Development Kit(JDK)




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


Eclipse IDE for Java




Android Development Tool(ADT)


 

Install JDK


Download Java SE Development Kit




http://www.oracle.com/technetwork/java/javase/downloads/index.html

Execute the downloaded file to install

Control Panel > System > Advanced, Select Environment Variables Set environment variable PATH to your JDK install path

JDK install path

15

Install Android SDK




Download Android SDK




http://developer.android.com/sdk/index.html If installer failed to find JDK under 64bit Windows, then click Back and Next button again

Execute the downloaded file to install




Choose packages and install them, default is enough


Select packages to install

16

Install Eclipse IDE




Download Eclipse IDE for Java




http://www.eclipse.org/downloads/

  

Unzip the downloaded file Execute eclipse.exe to open IDE Set workspace to your working directory

Your working directory

17

Install Eclipse ADT


  

Start eclipse Select Help > Install New Software Click Add and Add Repository with the following URL


https://dl-ssl.google.com/android/eclipse/

Accept the license agreement and finish


ADT repository URL

18

Configure Eclipse more




Have Eclipse know where the Android SDK is


  

Open the menu Windows>Preferences Set SDK Location to your Android SDK path Apply to list available android targets
Your Android SDK path

19

Create Android Virtual Device




Android Virtual Device(AVD) is a android emulator




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

Create your own AVD


   Donut(1.6) Eclair(2.1) Froyo(2.2) Gingerbread(2.3) Honeycomb(3.0)

20

Hello Android!


Try creating a new android project


  

File>New>Project, Select Android Project Select build target Write down properties


Application name: the title of this app




Hello Android eecs.seminar.shim Main 7 for eclair

Package name: where sources to be located




Create Activity: create with a new activity




Min SDK Version: minimum SDK version to guarantee




21

Run Hello Android !




Run this application by


  

menu Run>Run or button on toolbar or Ctrl+F11

Your AVD displays the result like below

22

Basic Structure of Hello Android




HelloAndroid project consists of




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

Strings of Hello Android




Where does this string come from?


Where can I modify it to Hello Android ?


res>values folder contains string resources

To see the string, open strings.xml file


 

Modify the value of field hello to Hello Android There s the other field app_name , the title 24

Layout of Hello Android




If so, where is the point the string is loaded?




res>layout folder contains layout files

 

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


Sure, the android:text= @string/hello might be Hello Android

25

More about Layout




Android provides lots of layout and widget objects




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

Prepare for Interactive Hello Android




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

The id of this button is button1

27

Interactive Hello Android




To have the button listen a event, the source code Main.java should be rewritten
import necessaries

get a reference to the button

whenever the button is clicked, it shows a message box called Toast

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

Android Application Development: Debugging


Kyuseok Shim EECS, SNU

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

Debugging Tools in Android




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

Eclipse ADT plug-in performs based on ADB and DDMS




e.g. Running an app in Eclipse consists of two ADB commands: install and start 32

Debugging in Android


Running in debug mode




By clicking or menu Run>Debug Uses Java debug perspective as usual




Call Stack

Variables

Thanks to ADT and debugger tools in SDK Setting breakpoints Step-by-step execution Watching variables Check the current call stack

Available debugger features


   

Source View

Breaks here currently

33

Logging in Android, System




Android Logging system collects debug output from various applications




Especially, collecting system errors is important

 

Android LogCat dumps a log collected ADT provides LogCat window for Eclipse


Window>Show View>Other , Android>LogCat

34

Logging in Android, Your App.




Log is a logging class


 

Can be utilized in your code Prints out messages to the LogCat




Similar to printf or std::cout in console program Log.v, Log.d, Log.i, Log.w, Log.e Verbose, debug, information, warning, error

5 methods for 5 different priorities


 

35

Other tools from Android SDK




Window>Show View>Other /Android




File Explorer


Pull, push, and delete files

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

Layout View/Tree View


 

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

Potrebbero piacerti anche