Você está na página 1de 13

Hands-On-Android

An Introduction to Android Application Programming

Session 0 : Introduction

Thinking like an Android Developer


The Android Software Developers Kit
Project structure
Working with layouts and images
Playing with SDK samples

Hands-On-Android, Loeb & Angrave


04/27/17 1
2010
Welcome!

Your hosts today are


Lawrence
Alex

Hands-On-Tutorial, Loeb & Angrave


04/27/17 2
2010
Is it easy to master Android Programming?

API Features
2D and 3D Graphics
Layouts and views
SQL Database
Sensors, Cameras,
Broadcast Intents and Receivers
Live desktop

Performance on a low resource machine


Breaking OO Rules
Activity Lifecycle
GUI Thread and handlers
Background Threads & Background Services
Battery Life. Connectivity failures
Hands-On-Tutorial, Loeb & Angrave
04/27/17 3
2010
About Today

Is it a guided tour?
A laundry list of tips and tricks?
A Jumping off point?
A chance to make mistakes?
A chance to meet others?

Hands-On-Tutorial, Loeb & Angrave


04/27/17 4
2010
Your Android SDK directory

docs/
guide A comprehensive introductory guide
resources FAQs, Articles, Howtos and Best
Practices
reference javadoc (Java class documentation)

samples sample code


tools useful command line tools for specific
tasks
platforms different versions of Android systems
addons Google extras e.g. Maps API

Hands-On-Tutorial, Loeb & Angrave


04/27/17 5
2010
Use adb to talk to device (or emulator)

SDK/tools must be on your path otherwise cd


to the correct directory.
Open a terminal (dos window).
Phone: Settings>Applications>Allow USB Debugging
Start emulator / attach your phone then

Try it!
adb logcat . Useful to have logcat running all
the time.
adb shell (then ls)
adb (will list all adb commands)

Useful: adb push/pull to transfer files and directories


Hands-On-Tutorial, Loeb & Angrave
04/27/17 6
2010
Other command line tools exist
android (android ) A script that lets you manage AVDs and generate Ant build files that you can use to compile your
Android applications.
Android Debug Bridge ( adb ) The adb tool lets you install your application's .apk files on an emulator or device and access
the emulator or device from a command line. You can also use it to link a standard debugger to application code running
on an Android emulator or device.

Hierarchy Viewer The Hierarchy Viewer tool allows you to debug and optimize your user interface. It provides a visual
representation of your layout's hierarchy of Views and a magnified inspector of the current display with a pixel grid, so
you can get your layout just right.
layoutopt This tool lets you quickly analyze your application's layouts for efficiency.

UI/Application Exerciser Monkey The Monkey is a program that runs on your emulator or device and generates pseudo-
random streams of user events such as clicks, touches, or gestures, as well as a number of system- level events. You can
use the Monkey to stress-test applications that you are developing, in a random yet repeatable manner

zipalign An important .apk optimization tool. This tool ensures that all uncompressed data starts with a particular alignment
relative to the start of the file. This should always be used to align .apk files after they have been signed.
Dalvik Debug Monitor Service (ddms) Integrated with Dalvik, the Android platform's custom VM, this tool lets you manage
processes on an emulator or device and assists in debugging. You can use it to kill processes, select a specific process to
debug, generate trace data, view heap and thread information, take screenshots of the emulator or device, and more.
Traceview This tool produces graphical analysis views of trace log data that you can generate from your Android application.

sqlite3 Included as a convenience, this tool lets you access the SQLite data files created and used by Android applications.

Android Emulator A QEMU-based device-emulation tool that you can use to design, debug, and test your applications in an
actual Android run-time environment.
Draw 9-patch The Draw 9-patch tool allows you to easily create a NinePatch graphic using a WYSIWYG editor. It also previews
stretched versions oft he image, and highlights the area in which content is allowed.
dx The dx tool rewrites .class bytecode into Android bytecode (stored in .dex files.)
Android Asset Packaging Tool (aapt) The aapt tool lets you create .apk files containing the binaries and resources of Android
applications. Android Interface Description Language (aidl) Lets you generate code for an interprocess interface, such as
what a service might use.
mksdcard Helps you create a disk image that you can use with the emulator, to simulate the presence of an external storage
card (such as an SD card).

Hands-On-Tutorial, Loeb & Angrave


04/27/17 7
2010
Android Project

Look at HelloWorld project

Hands-On-Tutorial, Loeb & Angrave


04/27/17 8
2010
Android Project Structure

src/
Your Java files for your application go here in subdirectories.
gen/
Contains Java files automatically generated such as your
R.java file.
res/
Contains app resources, such as images, layout files, string
values.
assets/ Optional
You can use it to store other raw asset files.

AndroidManifest.xml
Describes the contents of your application.

default.properties
This file contains Android project settings. Do not edit it directly
instead right-click the project folder and select "Properties".

Hands-On-Tutorial, Loeb & Angrave


04/27/17 9
2010
Introducing Layouts

xml file that describes how to layout a set of window


components.
e.g. chesslayout.xml

<LinearLayout >
<ImageView > </ImageView >
<TextView > </TextView>
<TextView > </TextView>
</LinearLayout>

Many attributes. Eclipse wizard. More about this in


Session 1.
Can create custom components.
Hands-On-Tutorial, Loeb & Angrave
04/27/17 10
2010
Project Layout
Java classes are compiled when you save them
src/game/chess/GameActivity.java
Compiled to .class .. which is translated into
Androids .dx format

Strings, Images, Views, Layouts etc go in res


subdirectory
Integer constants appear in R.java so that you can
easily use the resource from Java

Output?
Everything zipped up into a single apk file
To manually install adb install chess.apk ; but lets use
Eclipse
Hands-On-Tutorial, Loeb & Angrave
04/27/17 11
2010
Images and layouts

Put
chesslayout.xml in res/layout
bishop.png in res/drawable

Entries in R.java magically appear.


Dont control or care about the actual integer values.

gen/game/chess/R.java
public final class R {
public static final class drawable {
public static final int bishop=0x7f020002;

Your Java code


setContentView(R.layout.chesslayout);
mBishop = getDrawable(R.drawable.bishop);
Hands-On-Tutorial, Loeb & Angrave
04/27/17 12
2010
Now

Session 1 @ 10am My first app


views,layouts,manifest,activities.

Now Playtime

Create New Android Project from APIDemos sample and


from Notepad sample
Run them on your phone/emulator.
Explore the source code and resources.

Hands-On-Tutorial, Loeb & Angrave


04/27/17 13
2010

Você também pode gostar