You are on page 1of 20

1

1 Java
Java Android Java
Java Java

Android Java JavaSE5 Android


Dalvik Java
Java Java
{}
1Java
Java 8
$
$ Java

2.1

boolean
Char
Int

Flag
Ch
Counter

true
\u12ab
5

boolean Flag = true;


char ch = \u12ab;
int counter = 5;

2
Java

2.2

1
2
3
4
5
6
7
8
9
10
11
12
13
14

()[]
! + - ~ ++ -*/%
+-
<< >> >>>
< <= > >= instanceof
= = !=
&
^
|
&&
||
?:
= += -= *= /= %= &= |= ^= ~= <<= >>= >>>=

1
14
7+-9 7 -9
3
if switch if

if
;
[else ;]

if if else
Java
if-else
? :

Switch if switch
case
break switch break
case
switch{
case 1: 1; break;

case N : N; break;
default: ;
}

while
while

do-while
do

while;

for

for;;

break
4
Java Java

Java try-catch
try-catch
try {

;
} catch ( ) {

catch catch
catch
Java throws
throw
5
Java class

01 public class Person {


02 public String leg ="";
03 public void run(){
04
System.out.println("" + leg + "");
05 }
06 public static void main(String[] args) {
07
Person person = new Person();
08
person.run();
09 }
10 }

Person main()
Person person
Java
Java Java
6 Java
Java
Android

Java Java API


Java
Java
Java
Java IO
Java

Java

2 Android
Android

IDE

Windows2003Windows XP
Vista
Mac OS X 10.4.8
(x86)
Linux ( Linux Ubuntu Dapper
Drake )
Java SE Development Kit

JDK5JDK6
JRE

Android SDK
Eclipse3.5
GalileoEclipse3.4Gany
mede
Eclipse3.3Europa
Android Development
ToolsADT
Apache Ant

Eclipse JDT WST

Linux Mac1.6.5
, Windows
1.7

http://java.sun.com/javase/do
wnloads/index.jsp
http://developer.android.com/i
ntl/zh-CN/sdk/index.html
http://www.eclipse.org/downl
oads/

http://dl.google.com/android/
ADT-15.0.0.zip
http://ant.apache.org/bindownl
oad.cgi

Android
Eclipse Android Development ToolsADT
Android SDK 4.0

2.7 android SDK

3 Java
Java JDK Sun IE
http://java.sun.com/javase/downloads/index.jsp Java JDK

2.8 Java JDK

platform Windows 2.10


Skip this Step

2.9 LogIn for Download

exe
Next
Java version
Java
Linux platform Linux bin
Linux Java

4 Android SDK
Java JDK Android SDK
http://developer.android.com/intl/zh-CN/sdk/index.html SDK
Windows

2.10 Android SDK

SDK Setup.exe
Failed to fetch

2.11

Android SDK and AVD Manager Settings


MiscForce https:// https http Save &
Appley

2.11

Available Packages Android API USB


SDK

2.12

Install Selected

SDK android-sdk-windows-1.5_r3

Android SDK
path ,
, ,
Administrator Administrator

Path E:\android-sdk_r04windows\android-sdk-windows\tools;
2.11

2.13 Android SDK

android adb Android

5 Eclipse
Eclipse IBM Java Eclipse
Java JDTJava Development Tools Eclipse

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

Eclipse IDE for Java Developers (92 MB)


Eclipse Java Java CVS
XML Mylyn
eclipse-java-galileo-SR1-win32.zip Eclipse
Java JDKEclipse
Eclipse E:\eclipse
eclipse.exe
Eclipse Java JDK

JDK Eclipse

2.14 eclipse

Android ADT ADT


Android Eclipse
Android Development Tools Eclipse Eclipse
Android
EclipseADT Android
Eclipse IDE Android
Eclipse ADT DDMS

Android

Android
Android Android
XML
Android APK
Android
Eclipse ADT Eclipse
IDEhelpInstall New Software

2.15

InstallAdd...Add Site

10

2.16

OK http httpsOK
Developer Tools Next ADT
Eclipse

2.17 ADT

ADT
http://dl.google.com/android/ADT-15.0.0.zip zip Add Site
Archive zip
ADT Eclipse
Eclipse Eclipse 3.3

1 Eclipse Help > Software Updates > Find and Install...


2 Search for new features to install Next
3 New Remote Site
4 remote site URL https://dlssl.google.com/android/eclipse/
5 site Finish

11

6 , checkbox "Android Plugin". :


"Android DDMS" "Android Development Tools". Next.
7 license , Next.
8, Finish.
9 Eclipse
ADT Android SDK
WindowsPreferences Android SDK Location
browse... Android SDK 2.18

2.18 ADT Android SDK

SDK
Android SDK Android

6 Android AVD
Android 1.1 emulator
Android 1.5 AVD(Android Virtual Device)
AVD AVD
AVD AVD
AVD Android AVD
SD AVD

android list targets

2.19 Android id
id
API

12

2.19
android create avd --name sdk_1.5 --target 2

Android1.5

2.20 Android AVD

sdk_1.5 2 id 2
Android 1.5

android list avd

emulator -avd sdk_1.5

sdk_1.5 AVD
AVD
emulator -avd sdk_1.5 -skin HVGA-L

android list avd


AVD Path
Android AVD Eclipse ADT

13

AVD Eclipse WindowAndroid SDK and


AVD Manager

2.21 AVD

Android SDK Virtual Devices


New...
Create new AVD AVD nameTargetCreate AVD

2.22 ADT

Android Eclipse
2.22 Android SDK AVDStart...
AVD G1

14

7 Android
Windows Linux Eclipse ADT Android
SDK
Eclipse Eclipse
Eclipse
Android Eclipse FileNew
Android Project 2.23

2.23 Android Project

Android ProjectNew Android Project


Android
2.24 Project Name Demo_2 Contents
Create new project in workspace
Create project from existing source
Eclipse
Build Target Android1.5 Android
Application name LoveApp
com.hb3t Activity Activity
Activity
LoveActivity
Android

15

2.24 Android

FinishAndroid Android

2.25

Conversion to Dalvik format failed with error


1 Eclipse ProjectClean Eclipse

8
I love Android
src LoveActivity.java Activity
I

16

love Android Activity

2.26

setContentView(R.layout.main)
gen R.java Eclipse

2.27

gen
R.java

2.28 gen R.java

R.java
I love AndroidLoveActivity
strings.xml

17

2.29 strings.xml

strings.xml XML
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, LoveActivity!</string>
<string name="app_name">LoveApp</string>
</resources>

<?xml version="1.0" encoding="utf-8"?>


<resources>
<string name="hello">I love Android!</string>
<string name="app_name">LoveApp</string>
</resources>

main.xml
layout main.xml

2.30 main.xml

layout

2.31

18

ADT UI
UI
Android
strings.xml main.xml Activity Acitvity
main.xml main.xml TextView
strings.xml

9
Eclipse ADT
Package Explorer Demo_2Run As
Android Application

2.32

ADT Android Android Android

2.33

19

menu
Android
Sorry!(in process )is not responding
Wait

2.34

Eclipse

Eclipse Run AsRun


Configurations... Android Android

2.35

Android Android

20

USB

USB
Windows Android USB
Debug
Eclipse

10
Eclipse ADT Debug

2.36

Debug AsAndroid Application

2.37

2.37
Java LogCat Android
.