Android Developer Intro

24
Android Developer Introduction Eric Faccer [email protected] Tricorder

Transcript of Android Developer Intro

Page 1: Android  Developer Intro

Android Developer Introduction

Eric [email protected]

Tricorder

Page 2: Android  Developer Intro

Presentation Overview

• Dream/ADP1 Handset Overview• The Android SDK• The Android Software Stack• Advanced Concepts• Web Resources

Page 3: Android  Developer Intro

HTC Dream

• Qualcomm ARM based CPU• Camera• Accelerometer• GPS, Digital Compass• WIFI, Bluetooth• TouchScreen• 3D Graphics

Page 4: Android  Developer Intro

Other Devices• Openmoko FreeRunner• Motorola A1200 Ming• HTC Vogue• HTC Touch• Nokia N810• Nokia 770• Asus EEEPC 701• Asus EEEPC 1000H• Always Innovating Touch Book• Dell Axim x51v

Page 5: Android  Developer Intro

Open Handset Alliance• Mobile Phone Consortium dedicated to open

standards for mobile devices.

• Google, HTC, Intel, Samsung, Motorola, Qualcomm, T-Mobile, Sprint Nextel, Nvidia, Sony Ericsson, Vodaphone, ARM Holdings, Asustek, Toshiba, Garmin.

• Nokia has hedged their bets and reportedly has a large team working on android.

Page 6: Android  Developer Intro

What is Android• Custom Linux Distribution and Java-based Virtual Machine

• Based on the Java language 1.5 standard

• Java is an overloaded term. It refers to:– A language with a distinct syntax/grammar– A class library– A stack based virtual machine

• Android has implemented their own VM called Dalvik. Dalvik is different because it uses a register based VM architecture.

• The practical consequence of the decision to drop the Java VM is standard java classes cannot be used on android without conversion.

Page 7: Android  Developer Intro

What is Android

Page 8: Android  Developer Intro

SDK Demo & Tools Overview

• Eclipse Plugin• DDMS• HierarchyViewer

• Activitycreator• Aapt Tool• Dx

Page 9: Android  Developer Intro

Activity class• Roughly corresponds to a single “screen”

• Your application’s entry point.

• Does not require a user interface, but that would be atypical.

• When a new screen opens, the previous screen is paused and put onto a history stack. The user can then navigate backwards through previously opened screens in the history. Screens can also be removed from the history stack when it would be inappropriate for them to remain.

Page 10: Android  Developer Intro
Page 11: Android  Developer Intro

Service class

• Application component that runs in the background, for an indefinite period of time.

• OpenBinder – System Level IPC and Component Framework

• Local Services and Remote Services• Remote Services require using aidl and

Parcelable classes

Page 12: Android  Developer Intro

Activity or Service Blocking

• Use Threads liberally.

• If your application or service blocks, the ActivityManager will come over and throw up a nasty ANR error for Application Not Responding.

• If you start getting these, you know what to do.

Page 13: Android  Developer Intro

AndroidManifest.xml

• A means for publishing application metadataService Registration:<service android:name= "org.tricorder.android.TableService" />

Permissions:<uses-permission android:name="android.permission.INTERNET" /><uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

Intent-Filters:<intent-filter>

<action android:name="org.tricorder.android.generic.service.ITrackerService"/><action android:name="org.tricorder.android.generic.service.REMOTE_SERVICE"/>

</intent-filter>

Page 14: Android  Developer Intro

Intent class

• An intent is a description of an operation to be performed.

• It can be used with Activity.startActivity() to launch an Activity or Context.BindService() to communicate with a Service. It can be broadcast system-wide to send it to any interested BroadcastReceiver components

Page 15: Android  Developer Intro

Intent ExampleIntent myIntent = new Intent(

android.content.Intent.ACTION_VIEW, Uri.parse("geo:38.899533,-77.036476"));

startActivity(myIntent);

Will open up the Maps Activity with the specified coordinates.

Page 16: Android  Developer Intro

Resources• Android SDK apps have no access to the

underlying filesystem (except /sdcard)• Resources are build time artifacts (files) that are

included in your application package.

res/drawable – for images png/jpg, etc.res/layout – for xml layout filesres/menu – for xml based menu specificationsres/values – for strings, dimensions, etc.res/anim – for animations

res/raw – for raw files

Page 17: Android  Developer Intro

BroadcastReceiver• A means to respond to system level events

• The interface consists of a single method:onReceive() { }

• To use in your Activity:• registerReceiver() in your Activity’s onResume() callback• unRegisterReceiver() in your Activity’s onPause() method

• You can’t use it as an arbitrary message bus, because it will miss messages when the it’s Activity is inactive.

• This holds even if you fail to unregister the receiver. Unregistering the receiver is merely good practice that reduces the system overhead by a small amount.

Page 18: Android  Developer Intro

Content Provider

• A means for sharing tabular data across applications

• It is a class that implements a standard set of methods to let other applications store and retrieve the type of data that is handled by that content provider.

• Uses sqlite backend for relational data storage

Page 19: Android  Developer Intro

Android User Interface• May be defined using XML files or by writing standard

java code

• XML Caveats– The XML parser and renderer have a lot of bugs.

This crashes eclipse alot. <?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="wrap_content" android:layout_height="wrap_content“ android:text="Hello World"/>

</LinearLayout>

HINT: USE WRAP_CONTENT! WYSIWYG tool at droiddraw.org

Page 20: Android  Developer Intro

Layouts• FrameLayout

– contains a single object• LinearLayout

– aligns all children in a single direction• TableLayout

– positions its children into rows and columns• AbsoluteLayout

– absolute positioningRelativeLayout

– children specify their position relative to the parent view or to each other

Page 21: Android  Developer Intro

Handling UI events

• Handle events the standard way:• EventListeners

– onClick()• EventHandlers

– onTouchEvent(MotionEvent)

Page 22: Android  Developer Intro

Crossing Things Off of Lists

Credit: Jeff Sharkeyhttp://www.jsharkey.org/blog

Page 23: Android  Developer Intro

Further Reading

• http://developer.android.com• http://android-dls.com/wiki/• http://anddev.org• #android, #android-dev on

irc.openprojects.net

• http://source.android.com

Page 24: Android  Developer Intro

Advanced Concepts

• http://www.v6pc.jp/apc/en/data/addressing.pdf

• http://www.open802.11s.org• http://www.quagga.net/about.php