Hey,
Robot!

A
casual
introduc5on
to
Android

      development
in
Java


         Ron
DuPlain

   ron.duplain@gmail.com

...
Discussion
Goals

•    provide
an
Android
overview

•    highlight
the
(free)
Android
Java
SDK

•    introduce
Android
app...
Android
Overview





   Android
@
Richmond
JUG
‐
July
15,
2009

one‐page

•  “Android
is
a
soYware
stack
for
mobile
devices

   that
includes
an
opera5ng
system,
middleware

   and
key
a...
Architecture





h@p://developer.android.com/guide/basics/what‐is‐android.html

              Android
@
Richmond
JUG
‐
Ju...
Android
Devices

•  HTC/T‐Mobile
G1

•  HTC
Magic

•  “At
Least
18
Android
Phones
Coming
This
Year”

•  h@p://www.business...
Android
Development

•  Android
Java
SDK,
with
Eclipse
IDE
support

•  Android
C/C++
Na5ve
Development
Kit

  –  addon
to
...
Android
Development

•  Android
Java
SDK,
with
Eclipse
IDE
support

•  Android
C/C++
Na5ve
Development
Kit

  –  addon
to
...
Android
Developers

•    sign
up
for
$25

•    publish
applica5ons
to
the
Android
Market

•    Market:
free
or
paid

•    ...
Android
Java
SDK





  Android
@
Richmond
JUG
‐
July
15,
2009

SDK
Overview

•  full‐featured
emulator

•  Android
Development
Tools
(ADT)
plugin

   for
Eclipse
IDE

•  suite
of
tools
...
SDK
Overview

•  full‐featured
emulator
(no
device
needed)

•  Android
Development
Tools
(ADT)
plugin

   for
Eclipse
IDE
...
SDK
Installa5on

•    h@p://developer.android.com/sdk

•    Windows,
Mac,
GNU/Linux,
x86
plaqorms
only

•    grab
zip
for
...
Not
using
Eclipse?

•  h@p://developer.android.com/guide/
   developing/other‐ide.html


•  walks
through
tools
usage
to
e...
Eclipse
Integra5on





   Android
@
Richmond
JUG
‐
July
15,
2009

Emulator





Android
@
Richmond
JUG
‐
July
15,
2009

Grab
Screenshots

•  emulator
or
device





                 Android
@
Richmond
JUG
‐
July
15,
2009

Applica5on
Fundamentals





      Android
@
Richmond
JUG
‐
July
15,
2009

Applica5on
Components

•    Ac?vity
–
foreground,
with
UI

•    Service
–
background,
no
UI

•    BroadcastReceiver
–
for
...
Ac5vity
Lifecycle





  Android
@
Richmond
JUG
‐
July
15,
2009

Service
Lifecycle





  Android
@
Richmond
JUG
‐
July
15,
2009

Resources,
Layout,
UI

•  store
strings,
colors,
constants,
drawables,
etc
in

   project/res/

•  Android
auto‐generates
...
Manifest

•  define
applica5on
components,
request

   permissions
in
AndroidManifest.xml

•  (examples
coming)





      ...
Intents

•    call
out
to
an
ac5vity,
a
service,
or
receivers

•    can
call
within,
or
to
other
applica5ons

•    bundle
...
Ammuni5on

•    Intents

•    ContentProviders

•    sqlite3

•    drawables/layouts
(borrow
from
free
projects)





    ...
Status/No5fica5on
Bar





     Android
@
Richmond
JUG
‐
July
15,
2009

Notable
Features

•    can
run
in
background
as
service

•    intents

•    broadcast
intent
‐>
applica5on

•    status/no...
Android
Examples


from
open
source
applica5ons





       Android
@
Richmond
JUG
‐
July
15,
2009

Outline
of
Examples

•  BroadcastReceiver
&
AndroidManifest.xml

   –  SMSPopup’s
SMSReceiver

   –  h@p://code.google.com...
BroadcastReceiver

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent...
AndroidManifest.xml

<receiver android:name=".SMSReceiver">
  <intent-filter>
    <action android:name="android.provider.T...
Result





Android
@
Richmond
JUG
‐
July
15,
2009

Service

public class AlarmService extends Service {
    private static final String TAG = LogConstants.TAG;
    private s...
Result





Android
@
Richmond
JUG
‐
July
15,
2009

Ac5vity,
when
loaded





    Android
@
Richmond
JUG
‐
July
15,
2009

Layout

res/layout/countdown_editor.xml:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    andro...
Strings

res/values/strings.xml:


<?xml version="1.0" encoding="utf-8"?>
<resources>
  ...
  <string name="hint_title">e....
R.java

public final class R {
    ...
    public static final class id {
        ...
        public static final int coun...
Ac5vity

public class CountdownEditorActivity extends Activity {
    ...
    private TextView mCountdownView;
    ...
    ...
Result





Android
@
Richmond
JUG
‐
July
15,
2009

Result





Android
@
Richmond
JUG
‐
July
15,
2009

Conclusions





Android
@
Richmond
JUG
‐
July
15,
2009

Key
Takeaways

•  app
integra5on
through
intents

•  apps
can
run
in
mul5ple
ways:

   –  in
the
foreground,
with
a
UI
(Ac...
Android
Developer
Challenge

•    h@p://code.google.com/android/adc/

•    open
submission
August
1‐31,
2009

•    win
up
...
Get
Started

Start
here:

•  h@p://developer.android.com/
‐
overview

•  h@p://source.android.com/
‐
source
code

Look
for...
Upcoming SlideShare
Loading in...5
×

Intro to Android

6,245

Published on

0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
6,245
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
386
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Transcript of "Intro to Android"

  1. 1. Hey,
Robot!
 A
casual
introduc5on
to
Android
 development
in
Java
 Ron
DuPlain
 ron.duplain@gmail.com
 @rduplain
 h@p://go.nrao.edu/android/talk
 Android
@
Richmond
JUG
‐
July
15,
2009

  2. 2. Discussion
Goals
 •  provide
an
Android
overview
 •  highlight
the
(free)
Android
Java
SDK
 •  introduce
Android
applica5on
fundamentals
 •  walk
through
real
examples

 *
I
am
not
affiliated
with
Google
or
any
part
of
the
Android
project.
 Android
@
Richmond
JUG
‐
July
15,
2009

  3. 3. Android
Overview
 Android
@
Richmond
JUG
‐
July
15,
2009

  4. 4. one‐page
 •  “Android
is
a
soYware
stack
for
mobile
devices
 that
includes
an
opera5ng
system,
middleware
 and
key
applica5ons.”
developer.android.com
 •  development
led
by
Google
 •  developed
by
the
Open
Handset
Alliance
 •  carried
first
by
T‐Mobile
(G1)
 •  open
source
(Apache
License)
 •  supported
by
hardware
vendors
 •  ported
by
hardware
enthusiasts
 •  applica5ons
on
an
Android
device
are
“equal”
 Android
@
Richmond
JUG
‐
July
15,
2009

  5. 5. Architecture
 h@p://developer.android.com/guide/basics/what‐is‐android.html
 Android
@
Richmond
JUG
‐
July
15,
2009

  6. 6. Android
Devices
 •  HTC/T‐Mobile
G1
 •  HTC
Magic
 •  “At
Least
18
Android
Phones
Coming
This
Year”
 •  h@p://www.businessweek.com/the_thread/ techbeat/archives/2009/05/ at_least_18_and.html
 •  Ported
to
other
devices
 •  h@p://groups.google.com/group/android‐por5ng
 Android
@
Richmond
JUG
‐
July
15,
2009

  7. 7. Android
Development
 •  Android
Java
SDK,
with
Eclipse
IDE
support
 •  Android
C/C++
Na5ve
Development
Kit
 –  addon
to
SDK,
support
for
na5ve
code
 •  Android
Scrip5ng
Environment
 –  Python,
Lua,
BeanShell
now
 –  expect
Ruby
and
JavaScript
later
 •  PhoneGap
(HTML
&
JavaScript)

 Android
@
Richmond
JUG
‐
July
15,
2009

  8. 8. Android
Development
 •  Android
Java
SDK,
with
Eclipse
IDE
support
 •  Android
C/C++
Na5ve
Development
Kit
 –  addon
to
SDK,
support
for
na5ve
code
 •  Android
Scrip5ng
Environment
 –  Python,
Lua,
BeanShell
now
 –  expect
Ruby
and
JavaScript
later
 •  PhoneGap
(HTML
&
JavaScript)

 Android
@
Richmond
JUG
‐
July
15,
2009

  9. 9. Android
Developers
 •  sign
up
for
$25
 •  publish
applica5ons
to
the
Android
Market
 •  Market:
free
or
paid
 •  paid
apps:
70%
to
developer,
~30%
to
carriers
 •  developers
can
purchased
unlocked
phones
 •  alterna5vely,
get
.apk
zip
bundles
to
users
 Android
@
Richmond
JUG
‐
July
15,
2009

  10. 10. Android
Java
SDK
 Android
@
Richmond
JUG
‐
July
15,
2009

  11. 11. SDK
Overview
 •  full‐featured
emulator
 •  Android
Development
Tools
(ADT)
plugin
 for
Eclipse
IDE
 •  suite
of
tools
(mostly
command‐line)
 –  debugging,
packaging,
&
installing
applica5ons

 –  querying
devices
 •  target
emulator
or
device
 Android
@
Richmond
JUG
‐
July
15,
2009

  12. 12. SDK
Overview
 •  full‐featured
emulator
(no
device
needed)
 •  Android
Development
Tools
(ADT)
plugin
 for
Eclipse
IDE
 •  suite
of
tools
(mostly
command‐line)
 –  debugging,
packaging,
&
installing
applica5ons

 –  querying
devices
 •  target
emulator
or
device
 Android
@
Richmond
JUG
‐
July
15,
2009

  13. 13. SDK
Installa5on
 •  h@p://developer.android.com/sdk
 •  Windows,
Mac,
GNU/Linux,
x86
plaqorms
only
 •  grab
zip
for
your
plaqorm,
unpack
 •  add
SDK
tools
to
$PATH
/
%PATH%
 •  configure
IDE
 –  Eclipse
IDE
officially
supported
 –  Android
Development
Tools
(ADT)
plugin
 for
Eclipse
IDE
 Android
@
Richmond
JUG
‐
July
15,
2009

  14. 14. Not
using
Eclipse?
 •  h@p://developer.android.com/guide/ developing/other‐ide.html
 •  walks
through
tools
usage
to
enable
your
IDE
 to
 –  maintain
projects
 –  integrate
with
emulator
and
debugger
 Android
@
Richmond
JUG
‐
July
15,
2009

  15. 15. Eclipse
Integra5on
 Android
@
Richmond
JUG
‐
July
15,
2009

  16. 16. Emulator
 Android
@
Richmond
JUG
‐
July
15,
2009

  17. 17. Grab
Screenshots
 •  emulator
or
device
 Android
@
Richmond
JUG
‐
July
15,
2009

  18. 18. Applica5on
Fundamentals
 Android
@
Richmond
JUG
‐
July
15,
2009

  19. 19. Applica5on
Components
 •  Ac?vity
–
foreground,
with
UI
 •  Service
–
background,
no
UI
 •  BroadcastReceiver
–
for
specified
Intents
 •  ContentProvider
–
support
func5onality
 Android
@
Richmond
JUG
‐
July
15,
2009

  20. 20. Ac5vity
Lifecycle
 Android
@
Richmond
JUG
‐
July
15,
2009

  21. 21. Service
Lifecycle
 Android
@
Richmond
JUG
‐
July
15,
2009

  22. 22. Resources,
Layout,
UI
 •  store
strings,
colors,
constants,
drawables,
etc
in
 project/res/
 •  Android
auto‐generates
R.java,
access
resources
 •  build
UI
layouts
in
Java,
or…
 •  declare
UI
elements
in
XML,
manipulate
in
Java
 •  build/assign
listeners
to
UI
elements
(in
Java)
 Android
@
Richmond
JUG
‐
July
15,
2009

  23. 23. Manifest
 •  define
applica5on
components,
request
 permissions
in
AndroidManifest.xml
 •  (examples
coming)
 Android
@
Richmond
JUG
‐
July
15,
2009

  24. 24. Intents
 •  call
out
to
an
ac5vity,
a
service,
or
receivers
 •  can
call
within,
or
to
other
applica5ons
 •  bundle
“extras”
–
key/value
pairs
 •  “back
stack”
 Android
@
Richmond
JUG
‐
July
15,
2009

  25. 25. Ammuni5on
 •  Intents
 •  ContentProviders
 •  sqlite3
 •  drawables/layouts
(borrow
from
free
projects)
 Android
@
Richmond
JUG
‐
July
15,
2009

  26. 26. Status/No5fica5on
Bar
 Android
@
Richmond
JUG
‐
July
15,
2009

  27. 27. Notable
Features
 •  can
run
in
background
as
service
 •  intents
 •  broadcast
intent
‐>
applica5on
 •  status/no5fica5on
bar

 Android
@
Richmond
JUG
‐
July
15,
2009

  28. 28. Android
Examples
 from
open
source
applica5ons
 Android
@
Richmond
JUG
‐
July
15,
2009

  29. 29. Outline
of
Examples
 •  BroadcastReceiver
&
AndroidManifest.xml
 –  SMSPopup’s
SMSReceiver
 –  h@p://code.google.com/p/android‐smspopup/

 •  Service
 –  OI
Countdown’s
AlarmService
 –  h@p://code.google.com/p/openintents/
 •  Ac5vity,
layout,
and
R.java
 –  OI
Countdown’s
CountdownEditorAc5vity
 *
I
am
not
affiliated
with
these
projects.
See
websites
for
authors.
 Android
@
Richmond
JUG
‐
July
15,
2009

  30. 30. BroadcastReceiver
 import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; public class SMSReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Log.v("SMSReceiver: onReceive()"); intent.setClass(context, SMSReceiverService.class); intent.putExtra("result", getResultCode()); SMSReceiverService.beginStartingService(context, intent); } } Android
@
Richmond
JUG
‐
July
15,
2009

  31. 31. AndroidManifest.xml
 <receiver android:name=".SMSReceiver"> <intent-filter> <action android:name="android.provider.Telephony.SMS_RECEIVED”/> </intent-filter> <intent-filter> <action android:name="android.provider.Telephony.WAP_PUSH_RECEIVED”/> <data android:mimeType="application/vnd.wap.mms-message" /> </intent-filter> </receiver> Android
@
Richmond
JUG
‐
July
15,
2009

  32. 32. Result
 Android
@
Richmond
JUG
‐
July
15,
2009

  33. 33. Service
 public class AlarmService extends Service { private static final String TAG = LogConstants.TAG; private static final boolean debug = LogConstants.debug; Thread mThread; long mEndTime; @Override public void onCreate() { // Start up the thread running the service. Note that we create a // separate thread because the service normally runs in the process's // main thread, which we don't want to block. mThread = new Thread(null, mTask, "AlarmService"); mThread.start(); } ... } Android
@
Richmond
JUG
‐
July
15,
2009

  34. 34. Result
 Android
@
Richmond
JUG
‐
July
15,
2009

  35. 35. Ac5vity,
when
loaded
 Android
@
Richmond
JUG
‐
July
15,
2009

  36. 36. Layout
 res/layout/countdown_editor.xml: <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content" > <EditText android:id="@+id/title" android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_marginTop="10dip" android:layout_marginBottom="10dip" android:hint="@string/hint_title" /> ... </LinearLayout> </ScrollView> Android
@
Richmond
JUG
‐
July
15,
2009

  37. 37. Strings
 res/values/strings.xml:
 <?xml version="1.0" encoding="utf-8"?> <resources> ... <string name="hint_title">e.g. pizza</string> ... </resources> Android
@
Richmond
JUG
‐
July
15,
2009

  38. 38. R.java
 public final class R { ... public static final class id { ... public static final int countdown=0x7f08000a; ... public static final int title=0x7f080008; ... } ... } •  Just
know
that
it’s
auto‐generated.
 Android
@
Richmond
JUG
‐
July
15,
2009

  39. 39. Ac5vity
 public class CountdownEditorActivity extends Activity { ... private TextView mCountdownView; ... protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ... mCountdownView = (TextView) findViewById(R.id.countdown); ... } ... private void updateCountdown() { ... mCountdownView.setVisibility(View.VISIBLE); mCountdownView.setText("" + CountdownUtils.getDurationString(delta)); mCountdownView.setTextAppearance(this, android.R.style.TextAppearance_Large); mCountdownView.setTextSize(64); ... } ... } Android
@
Richmond
JUG
‐
July
15,
2009

  40. 40. Result
 Android
@
Richmond
JUG
‐
July
15,
2009

  41. 41. Result
 Android
@
Richmond
JUG
‐
July
15,
2009

  42. 42. Conclusions
 Android
@
Richmond
JUG
‐
July
15,
2009

  43. 43. Key
Takeaways
 •  app
integra5on
through
intents
 •  apps
can
run
in
mul5ple
ways:
 –  in
the
foreground,
with
a
UI
(Ac?vity)
 –  in
the
background,
without
a
UI
(Service)
 –  triggered
by
intent,
either
direct
or
broadcast
 (Ac?vity
or
BroadcastReceiver)
 •  third‐party
apps
can
replace
core
apps
 (“equal”)
 •  .apk
zip
bundles,
for
direct
install
or
market
 Android
@
Richmond
JUG
‐
July
15,
2009

  44. 44. Android
Developer
Challenge
 •  h@p://code.google.com/android/adc/
 •  open
submission
August
1‐31,
2009
 •  win
up
to
$250,000
USD
 •  winners
announced
~November
2009
 Android
@
Richmond
JUG
‐
July
15,
2009

  45. 45. Get
Started
 Start
here:
 •  h@p://developer.android.com/
‐
overview
 •  h@p://source.android.com/
‐
source
code
 Look
for
examples
in
Android
source.

See
also:
 •  h@p://code.google.com/p/openintents/
‐
large
 collec5on
of
samples
and
free
applica5ons
 •  h@p://code.google.com/p/bites‐android/
‐
cookbook
 •  h@p://code.google.com/p/trolly/
‐
shopping
list
 •  h@p://www.swiYp.org/
‐
FTP
server
for
the
device
 •  h@p://code.google.com/p/android‐smspopup/
‐
SMS
 •  (Thanks
to
@ben_caldwell
and
@callahad
for
5ps.)
 Android
@
Richmond
JUG
‐
July
15,
2009

  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×