Date post: | 07-Apr-2018 |
Category: |
Documents |
Upload: | taesik-yoon |
View: | 215 times |
Download: | 0 times |
of 37
8/6/2019 Introduction to Android Application_modified
1/37
Introduction to AndroidApplication
Kyuseok Shim
EECS, SNU
8/6/2019 Introduction to Android Application_modified
2/37
Android Architecture
Component diagram of the Android operating system Today, we are focusing on the application part 2
briefintroduction
somedetails
8/6/2019 Introduction to Android Application_modified
3/37
Core Libraries
A set of C/C++ libraries, which are built on Linux Kernel System C Library
Standard C library, tuned for embedded Linux
Media Libraries Playback and recording of audio and video
Surface Manager Display subsystem management Composites 2D/3D graphic layers
LibWebCore Embeddable web browser
SGL/3D Libraries 2D graphic engine, hardware 3D Acceleration
SQLite Relational database engine
3
8/6/2019 Introduction to Android Application_modified
4/37
Application Framework
Application Framework provides services and systems Use device hardware, access location information, set alarms,
add notifications to the status bar, and more
Application framework is composed of
Views View is a area for drawing and event handling e.g. buttons, lists, grids, and even web browser
Content Providers Access or share data among applications
e.g. contacts, and MediaStore
Resource Manager Access non-code resources e.g. localized strings, images, and layout files
Notification Manager Display alerts in the status bar
Activity Manager Manages lifecycles of applications Provides a common navigation 4
8/6/2019 Introduction to Android Application_modified
5/37
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
, , , , ,
5
get, listen, request,
?
dont carewhat happens
actually
8/6/2019 Introduction to Android Application_modified
6/37
Application Components
Application building blocks Activities
A single screen with a user interface 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 Receivers6
Activity Stack
8/6/2019 Introduction to Android Application_modified
7/37
Application Components
Application building blocks
Activities
Services Run in background to perform long-
running operations
Once started, last until it is terminated
e.g. messenger service, music player Contents Providers
Broadcast Receivers
7
Running Services
Check if theresa new message
Monitoringphone usage
Playing music
in background
8/6/2019 Introduction to Android Application_modified
8/37
Application Components
Application building blocks
Activities
Services Contents Providers
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
Broadcast Receivers8
RegisteredContents Providers
ScheduleProvider
read
add
8/6/2019 Introduction to Android Application_modified
9/37
Application Components
Application building blocks
Activities
Services Contents Providers
Broadcast Receivers
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 notifier9
Phone
call
Phone callreceiver
broadcast
start activityfor phone call
Alarm
Alarmreceiver
start activityfor alarmbroadcast
Your appsAlarmReceiver
?
anythingyou want to do
about this alarm
8/6/2019 Introduction to Android Application_modified
10/37
Application Components
Application building blocks Activities
A single screen with a user interface
Services
Runs in background to perform long-running operations Contents Providers
Manages shared set of application data
Broadcast Receivers Responds to broad-cast events
You dont have to write all these components Required components depend on your apps purpose
A music player requires activities and services A dictionary consists ofactivities and content providers A SMS manager needs activities and broadcast receivers
10
8/6/2019 Introduction to Android Application_modified
11/37
Communications Between
Application Components Android application can start another applicationscomponent 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?
11
Id like to run an appcan get music
Intent
Run the selected appas the description of this intent
8/6/2019 Introduction to Android Application_modified
12/37
Summary
Android applications are built onAndroid application framework with
fruitful functionalitiesAndroid applications consist of four
components: Activity, Contents Provider,Service, and Broadcast Receiver
Android applications can activate orcommunicate with another applicationscomponent
12
8/6/2019 Introduction to Android Application_modified
13/37
Android ApplicationDevelopment: Get Started
Kyuseok Shim
EECS, SNU
8/6/2019 Introduction to Android Application_modified
14/37
Installation list
Java Development Kit(JDK)
For building java source code
Android SDK Contains Core SDK Tools and Components
Eclipse IDE for Java
For convenience in development
Android Development Tool(ADT)
Eclipse plug-in offered by android
Helps Eclipse to create and debug applications14
8/6/2019 Introduction to Android Application_modified
15/37
8/6/2019 Introduction to Android Application_modified
16/37
Install Android SDK
Download Android SDK http://developer.android.com/sdk/index.html
Execute the downloaded file to install If installer failed to find JDK under 64bit Windows, then
click Back and Next button again Choose packages and install them, default is enough
16
Select packages
to install
8/6/2019 Introduction to Android Application_modified
17/37
Install Eclipse IDE
Download Eclipse IDE for Java http://www.eclipse.org/downloads/
Unzip the downloaded file Execute eclipse.exe to open IDE Setworkspace to your working directory
17
Your working directory
8/6/2019 Introduction to Android Application_modified
18/37
Install Eclipse ADT
Start eclipse SelectHelp >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
18
ADT repository URL
8/6/2019 Introduction to Android Application_modified
19/37
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
19
Your Android SDK path
8/6/2019 Introduction to Android Application_modified
20/37
Create Android Virtual Device
Android Virtual Device(AVD) is a android emulator acts like a real device except for a few limitations
Create your own AVD 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
Donut(1.6)Eclair(2.1)Froyo(2.2)
Gingerbread(2.3)Honeycomb(3.0)
8/6/2019 Introduction to Android Application_modified
21/37
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
Package name: where sources to be located eecs.seminar.shim
Create Activity: create with a new activity Main
Min SDK Version: minimum SDK version to guarantee 7 for eclair
21
8/6/2019 Introduction to Android Application_modified
22/37
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
8/6/2019 Introduction to Android Application_modified
23/37
Basic Structure of Hello Android
HelloAndroid project consists ofSrc folder
Java files to be implemented
gen folderAuto-generated java files
assets folderAny files you want to ship with
res folder Resources such as images, layouts and fonts
AndroidManifest.xml file Essential information about the application
23
8/6/2019 Introduction to Android Application_modified
24/37
Strings of Hello Android
Where does this string come from?
24
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
Theres the other field app_name, the title
8/6/2019 Introduction to Android Application_modified
25/37
Layout of Hello Android
If so, where is the point the stringis loaded? res>layout folder contains layout files
2
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
8/6/2019 Introduction to Android Application_modified
26/37
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,
Widget object UI element displayed on screen Corresponds to the event such as clicking, mouse over, e.g. TextView, Button, DatePicker, Gallery, WebView,
26
Layouts Widgets
8/6/2019 Introduction to Android Application_modified
27/37
Prepare for Interactive Hello Android
Just setting up the layout is not enough to makean android application
Instead of a boring app, to make more interactiveapp, lets 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
The id of this buttonis button1
8/6/2019 Introduction to Android Application_modified
28/37
Interactive Hello Android
To have the button listen a event, thesource code Main.java should be rewritten
28
import necessaries
get a reference to the button
whenever the button is clicked,
it shows a message box called Toast
8/6/2019 Introduction to Android Application_modified
29/37
Summary
To develop android applications, it isrequired to install JDK, Android SDK,Eclipse IDE, Eclipse ADT plug-in
To test android applications, usuallyAndroid Virtual Device(AVD) is enough
Android offers a variety of UI elements
and containers for layoutAll the Android UI elements can handle
events such as click and touch for userinteraction
29
8/6/2019 Introduction to Android Application_modified
30/37
Android ApplicationDevelopment: Debugging
Kyuseok Shim
EECS, SNU
8/6/2019 Introduction to Android Application_modified
31/37
Debugging
Most software developers suffers from thefault or malfunction of their program
Debugging is the process finding errors orbugs and making the program run in thedesired way
Debugger is a program used to test and
debug other programs, nowadaysdebuggers become important to save timeand effort for software development
31
8/6/2019 Introduction to Android Application_modified
32/37
Debugging Tools in Android
Android Debug Bridge(ADB) and Dalvik DebugMonitor 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
8/6/2019 Introduction to Android Application_modified
33/37
Debugging in Android
Running in debug mode By clicking or menu
Run>Debug
Uses Java debug perspectiveas usual Thanks to ADT and debugger
tools in SDK
Available debugger features Setting breakpoints
Step-by-step execution
Watching variables
Check the current call stack
33
Breaks herecurrently
Call Stack Variables
Source View
8/6/2019 Introduction to Android Application_modified
34/37
Logging in Android, System
Android Logging system collects debug outputfrom 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
8/6/2019 Introduction to Android Application_modified
35/37
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
5 methods for 5 different priorities Log.v, Log.d, Log.i, Log.w, Log.e Verbose, debug, information, warning, error
35
8/6/2019 Introduction to Android Application_modified
36/37
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
8/6/2019 Introduction to Android Application_modified
37/37