Download Android: A 9,000rfoot Overview Agenda

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Android Overview
,*-#%.-/&&
,&0122234%%+&
56)#6.)7&
!"#$%&'"#()*+"&
!"#"$"*"&
,()*-"&
• 
• 
• 
• 
• 
• 
• 
• 
• 
marakana.com
,*-#%.-&8.9+%#:&
,*-#%.-&"*-&;"6"&
<=)&>+"?$&
,*-#%.-&>@A&
8)BB%&C%#B-D&
!".*&EF.B-.*(&EB%?$9&
,*-#%.-&G9)#&H*+)#4"?)&
@)IF((.*(&
>FJJ"#:&
1
Android Overview
8.9+%#:&
K22L&
'%%(B)&IF:9&,*-#%.-1&H*?M&
C%#$&%*&@"B6.$&9+"#+9&
K22N&
58,&,**%F*?)-&
O"#B:&>@A&
K22P&
'Q&,**%F*?)-&
>@A&QM2&R)B)"9)-&
K220&
'K&R)B)"9)-&
SFT?"$)1&@%*F+1&O?B".#&
,*-#%.-&"*-&;"6"&
Android Java =
Java SE –
AWT/Swing +
Android API
marakana.com
2
Android Overview
!"#$%&#'()!*+'
<=)&>+"?$&
marakana.com
3
Android Overview
U.*FV&A)#*)B&
Applications
Android runs on Linux.
Home
Linux provides as well as:
Hardware abstraction layer
Memory management
Process management
Networking
Users never see Linux sub system
Contacts
Phone
Browser
Other
Application Framework
Activity
Manager
Package
Manager
Window
Manager
Telephony
Manager
Content
Providers
Resource
Manager
View
System
Location
Manager
Notiication
Manager
Libraries
Surface
Manager
Media
Framework
SQLite
OpenGL
FreeType
WebKit
SGL
SSL
libc
Android Runtime
Core Libs
The adb shell command opens
Linux shell
Display
Driver
Camera
Driver
Keypad
Driver
WiFi
Driver
Delvik
VM
Linux Kernel
Flash
Driver
Binder
Driver
Audio
Driver
Power
Mgmt
W"X6)&U.I#"#.)9&
Bionic, a super fast and small
GPL-based libc library optimized
for embedded use
Surface Manager for composing
window manager with off-screen
buffering
2D and 3D graphics hardware
support or software simulation
Media codecs offer support for
major audio/video codecs
SQLite database
Applications
Home
Contacts
Phone
Browser
Other
Application Framework
Activity
Manager
Package
Manager
Window
Manager
Telephony
Manager
Content
Providers
Resource
Manager
View
System
Location
Manager
Notiication
Manager
Libraries
Surface
Manager
Media
Framework
SQLite
OpenGL
FreeType
WebKit
SGL
SSL
libc
Android Runtime
Core Libs
Display
Driver
Camera
Driver
Keypad
Driver
WiFi
Driver
Linux Kernel
Delvik
VM
Flash
Driver
Binder
Driver
Audio
Driver
Power
Mgmt
WebKit library for fast HTML
rendering
marakana.com
4
Android Overview
@"B6.$&
Dalvik VM is Google’s implementation of Java
Optimized for mobile devices
Key Dalvik differences:
Register-based versus stack-based VM
Dalvik runs .dex files
More efficient and compact implementation
Different set of Java libraries than SDK
,TTB.?"X%*&Y#"J)7%#$&
Activation manager controls the life
cycle of the app
Content providers encapsulate data
that is shared (e.g. contacts)
Resource manager manages
everything that is not the code
Location manager figures out the
location of the phone (GPS, GSM,
WiFi)
Notification manager for events
such as arriving messages,
appointments, etc
marakana.com
Applications
Home
Contacts
Phone
Browser
Other
Application Framework
Activity
Manager
Package
Manager
Window
Manager
Telephony
Manager
Content
Providers
Resource
Manager
View
System
Location
Manager
Notiication
Manager
Libraries
Surface
Manager
Media
Framework
SQLite
OpenGL
FreeType
WebKit
SGL
SSL
libc
Android Runtime
Core Libs
Display
Driver
Camera
Driver
Keypad
Driver
WiFi
Driver
Linux Kernel
Delvik
VM
Flash
Driver
Binder
Driver
Audio
Driver
Power
Mgmt
5
Android Overview
,TTB.?"X%*9&
,*-#%.-&>@A&3&C="+Z9&.*&+=)&I%V&
SDK
Tools
Docs
Platforms
Data
Skins
Images
Samples
Add-ons
Google Maps
marakana.com
6
Android Overview
<=)&<%%B9&
Tools are important part of the
SDK. They are available via
Eclipse plugin as well as command
line shell.
,-..%'/%$.#0'
marakana.com
7
Android Overview
S#)"+)&W)7&[#%\)?+&
Use the Eclipse tool to create a new
Android project.
Here are some key constructs:
[#%\)?+&
O?B.T9)&?%*9+#F?+&
<"#()+&
J.*.JFJ&+%&#F*&
,TT&*"J)&
7="+)6)#&
["?$"()&
;"6"&T"?$"()&
,?X6.+:&
;"6"&?B"99&
<=)&!"*.4)9+&Y.B)&
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.marakana"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon"
android:label="@string/app_name">
<activity android:name=".HelloAndroid"
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>
<uses-sdk android:minSdkVersion="5" />
</manifest>
marakana.com
8
Android Overview
<=)&U":%F+&R)9%F#?)&
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
</LinearLayout>
<=)&;"6"&Y.B)&
package com.marakana;
import android.app.Activity;
import android.os.Bundle;
public class HelloAndroid extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
marakana.com
9
Android Overview
RF**.*(&%*&OJFB"+%#&
1!&"'23&.#&"4'2.%*+('
marakana.com
10
Android Overview
,?X6.X)9&
Activity is to an
application what a
web page is to a
website. Sort of.
Android Application
Main Activity
Another
Activity
Another
Activity
,?X6.+:&U.4)?:?B)&
Starting
Activities have a welldefined lifecycle. The
Android OS manages
your activity by
changing its state.
You fill in the blanks.
(1) onCreate()
(2) onStart()
(3) onRestoreInstanceState()
(4) onResume()
Running
(3) onResume()
(2) onStart()
(1) onRestart()
Stopped
(1) onSaveInstanceState()
(2) onPause()
onResume()
(1) onSaveInstanceState()
(2) onStop()
onDestroy()
or
<process killed>
Paused
<process killed>
Destroyed
marakana.com
11
Android Overview
H*+)*+9&
Android Application
Main Activity
Intent
Another
Activity
Intent
Intents are to
Android apps
what hyperlinks
are to websites.
They can be
implicit and
explicit. Sort of
like absolute and
relative links.
Android Application
Main Activity
Intent
Another
Activity
>)#6.?)9&
A service is something that can be started and
stopped. It doesn’t have UI. It is typically managed
by an activity. Music player,
for example
marakana.com
12
Android Overview
>)#6.?)&U.4)?:?B)&
Service also has a
lifecycle, but it’s
much simpler than
activity’s. An activity
typically starts and
stops a service to do
some work for it in
the background.
Such as play music,
check for new
tweets, etc.
Starting
(1) onCreate()
(2) onStart()
onStart()
Stopped
Running
onStop()
onDestroy()
or
<process killed>
Destroyed
S%*+)*+&[#%6.-)#9&
Content Providers share
content with applications
across application
boundaries.
Examples of built-in
Content Providers are:
Contacts, MediaStore,
Settings and more.
marakana.com
Content
Provider
Content URI
insert()
update()
delete()
query()
13
Android Overview
E#%"-?"9+&R)?).6)#9&
An Intent-based publish-subscribe mechanism. Great for listening
system events such as SMS messages.
!"#$%&#'3(-$'&")-$5!*-'
marakana.com
14
Android Overview
<7%&GH&,TT#%"?=)9&
6789:;<7=>'
#:9>=7=?@:'
]%F&7#.+)&;"6"&?%-)&
>.J.B"#&+%&>7.*(&%#&,C<&
]%F&7#.+)&^!U&?%-)&
>.J.B"#&+%&8<!U&%4&"&7)I&T"()&
You can mix and match both styles.
Declarative is preferred: easier and
more tools
^!U3E"9)-&G9)#&H*+)#4"?)&
Use WYSIWYG tools to build powerful XML-based UI.
Easily customize it from Java. Separate concerns.
marakana.com
15
Android Overview
@.T9&"*-&>T9&
AB'_T.V)B`&
@%+9&%*&+=)&9?#))*&
CD'_.*?=)9`&
>.a)&"9&J)"9F#)-&I:&"&#FB)#&
EE'_J.BB.J)+)#9`&
>.a)&"9&J)"9F#)-&I:&"&#FB)#&
AF'_T%.*+9`&
QbNK&%4&"*&.*?=&
;A'_-)*9.+:3.*-)T)*-)*+&T.V)B`&
,I9+#"?+&F*.+M&5*&9?#))*&7.+=&Qc2-T.1&
Q-TdQTV&
;CA&
9:*%*:J&4%#&-T&"*-&%e)*&F9)-&I:&'%%(B)&
GA&
>.J.B"#&+%&-T&IF+&"B9%&9?"B)-&I:&F9)#9&4%*+&
9.a)&T#)4)#)*?)&
f.)79&"*-&U":%F+9&
ViewGroup
ViewGroup
View
View
View
View
ViewGroups contain other Views but
are also Views themselves.
marakana.com
16
Android Overview
S%JJ%*&GH&S%JT%*)*+9&
Android UI includes many
common modern UI
widgets, such as Buttons,
Tabs, Progress Bars, Date
and Time Pickers, etc.
>)B)?X%*&S%JT%*)*+9&
Some UI widgets may
be linked to zillions of
pieces of data.
Examples are ListView
and Spinners
(pull-downs).
marakana.com
17
Android Overview
,-"T+)#9&
Adapter
Data
Source
To make sure they run smoothly, Android uses
Adapters to connect them to their data sources. A
typical data source is an Array or a Database.
S%JTB)V&S%JT%*)*+9&
Certain high-level components are simply
available just like Views. Adding a Map or a
Video to your application is almost like adding a
Button or a piece of text.
marakana.com
18
Android Overview
!)*F9&"*-&@."B%(9&
'#"T=.?9&g&,*.J"X%*&
Android has rich support for 2D graphics.
You can draw & animate from XML.
You can use OpenGL for 3D graphics.
marakana.com
19
Android Overview
!FBXJ)-."&
AudioPlayer lets you simply specify
the audio resource and play it.
VideoView is a View that you can
drop anywhere in your activity, point
to a video file and play it.
XML:
<VideoView
android:id="@+id/video"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center” />
Java:
player = (VideoView) findViewById(R.id.video);
player.setVideoPath("/sdcard/samplevideo.3gp");
player.start();
'%%(B)&!"T9&
Google Maps is an add-on in Android.
It is not part of open-source project.
However, adding Maps is relatively
easy using MapView.
XML:
<com.google.android.maps.MapView
android:id="@+id/map"
android:clickable="true"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:apiKey="0EfLSgdSCWIN…A"
/>
marakana.com
20
Android Overview
#-2344&"4''
!"#$%&#'!66('
U%(S"+&
The universal, most
versatile way to track
what is going on in
your app.
Can be viewed via
command line or
Eclipse.
Logs can be
generated both from
SDK Java code, or
low-level C code via
Bionic libc extension.
marakana.com
21
Android Overview
@)IF(()#&
Your standard debugger is included in SDK, with all the usual bells & whistles.
<#"?)f.)7&
TraceView helps you profile you application and find bottlenecks. It shows
execution of various calls through the entire stack. You can zoom into specific
calls.
marakana.com
22
Android Overview
8.)#"#?=:&f.)7)#&
Hierarchy Viewer helps
you analyze your User
Interface.
Base UI tends to be the
most “expensive” part of
your application, this tool
is very useful.
>FJJ"#:&
Android is based on Java.
You write Java code, but technically
don’t run it.
Java is augmented with XML, mostly
for UI purposes.
Android Java is mostly based on Java
SE with replacement UI libraries.
Marko Gargenta, Marakana.com
[email protected]
+1-415-647-7000
Licensed under Creative Commons
License (cc-by-nc-nd). Please Share!
marakana.com
23