Android for Java Developers
by Marko Gargenta
10 people last year at this talk at OSCON. This year: 100+
Writing an O'Reilly book: Learning Android.
Agenda
The Stack
Android SDK
Hello, World
Main Building Blocks
Android User Interface
Operating System Features
Debugging
Summary
The stack … good overview. See the graphic at http://developer.android.com/images/system-architecture.jpg.
Android Software Development Kit (SDK) … overview of what is included.
Using Eclipse is pretty standard but you don't have to. Android SDK included many command-line tools that integrate well with other Integrated Development Environments (IDEs).
SDK includes AVD Manager, a tool for creating Android Emulators. Version 1 of the SDK was released without any Android hardware (like the G1, Droid, Incredible, etc). Emulators can be created for many combinations and permutation of hardware abilities. For example: an emulators that doesn't have a camera, gps chip, et al. Can create mock sd_cards, etc. DDMS perspective in Eclipse can simulate GPS position, phone calls, SMSs, et al.
Review of $HOME/.android
ls avd
cat avd/.ini
“Hello, World”
(Basically going over: http://developer.android.com/resources/tutorials/hello-world.html)
http://www.google.com/
http://www.google.com/
Created a “Hello, OSCON” project in Eclipse
Review of what was created
~/workspace/HelloOSCON> ls
AndroidManifest.xml
assets/
bin/
default.properties
gen/
res/
src/
R.java is the glue between Java and XML. Bascially a bunch of pointers.
Review of Eclipse Android XML creator, for strings.xml for different languages, layout.xml for landscape views, et al.
http://www.google.com/
Review of /bin - .classes, .apk, et al.
The adb tool.
$ adb shell
$ ls
$ ps
$ adb --help
Android Debug Bridge version 1.0.26
Main Application Building Blocks
(The meat of the talk)
Activities – roughly, the screen.
An activity is to an application what a web page is to a website. Sort of.
Usually have a main activity.
Typically requires lotes of memory, processor needs.
One running at a time with many sleeping
Well defined lifecycle (see http://developer.android.com/images/activity_lifecycle.png)
How/when onCreate() gets called.
Intents – represents events or actions.
Like HTML hyper-links between webpages. Sort of.
Can be implicit or explicit.
See the Home application sameple.
The home button sends a “home” intent.
Services – a piece of code that runs in the background. No UI.
Well defined lifecycle.
Usually much lighter on resources than activities.
Content providers – interface to shared data between applications.
Content URI, insert(), update(), delete(), and query().
Android built-in examples: contacts, settings, et al.
Broadcast receivers – an Intent-based publish-subscribe mechanism.
For example: when an SMS arrives.
A review of his MyTwitter app to ties together all the building block consepts.
Android User Interface
Procedural: in Java
Declarative: in XML
Best approach uses both.
Hands-on developing a layout.
Views and Layouts
Linear Layouts...
Android units: dp (density-independent pixel)
dip (synonym)
sp (similar but also scaled by user for fonts)
In layouts, the order of siblings matters.
Layout weight property
“...” in the property editor in Ubuntu Eclipse is buggy
Write a little gui with Eclipse, main.xml
Connected with this Java:
package com.blogspot.oscon2010;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class MyTwitter extends Activity implements OnClickListener {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
EditText editTweet;
Button buttonUpdate;
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Find the views
editTweet = (EditText) findViewById(R.id.editTweet);
buttonUpdate = (Button) findViewById(R.id.buttonUpdate);
buttonUpdate.setOnClickListener(this);
}
public void onClick(View view) {
Log.d("Twitter", "Button clicked");
}
}
$ adb logcat # for viewing log via command-line


No comments:
Post a Comment