Your SlideShare is downloading. ×
0
Intro to Android
Intro to Android
Intro to Android
Intro to Android
Intro to Android
Intro to Android
Intro to Android
Intro to Android
Intro to Android
Intro to Android
Intro to Android
Intro to Android
Intro to Android
Intro to Android
Intro to Android
Intro to Android
Intro to Android
Intro to Android
Intro to Android
Intro to Android
Intro to Android
Intro to Android
Intro to Android
Intro to Android
Intro to Android
Intro to Android
Intro to Android
Intro to Android
Intro to Android
Intro to Android
Intro to Android
Intro to Android
Intro to Android
Intro to Android
Intro to Android
Intro to Android
Intro to Android
Intro to Android
Intro to Android
Intro to Android
Intro to Android
Intro to Android
Intro to Android
Intro to Android
Intro to Android
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Intro to Android

6,228

Published on

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

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

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 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. 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. Android
Overview
 Android
@
Richmond
JUG
‐
July
15,
2009

  • 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. Architecture
 h@p://developer.android.com/guide/basics/what‐is‐android.html
 Android
@
Richmond
JUG
‐
July
15,
2009

  • 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. 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. 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. 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. Android
Java
SDK
 Android
@
Richmond
JUG
‐
July
15,
2009

  • 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. 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. 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. 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. Eclipse
Integra5on
 Android
@
Richmond
JUG
‐
July
15,
2009

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

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

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

  • 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. Ac5vity
Lifecycle
 Android
@
Richmond
JUG
‐
July
15,
2009

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

  • 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. Manifest
 •  define
applica5on
components,
request
 permissions
in
AndroidManifest.xml
 •  (examples
coming)
 Android
@
Richmond
JUG
‐
July
15,
2009

  • 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. Ammuni5on
 •  Intents
 •  ContentProviders
 •  sqlite3
 •  drawables/layouts
(borrow
from
free
projects)
 Android
@
Richmond
JUG
‐
July
15,
2009

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

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

 Android
@
Richmond
JUG
‐
July
15,
2009

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

  • 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. 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. 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. Result
 Android
@
Richmond
JUG
‐
July
15,
2009

  • 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. Result
 Android
@
Richmond
JUG
‐
July
15,
2009

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

  • 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. 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. 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. 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. Result
 Android
@
Richmond
JUG
‐
July
15,
2009

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

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

  • 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. 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. 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


×