SlideShare a Scribd company logo
1 of 73
japan linux symposium
android development tutorial
                                                              tokyo, october 2009

                                                  diego torres milano
                                                     diego@codtech.com
    copyright © 2009  cod technologies ltd  www.codtech.com
“I have always wished that my 
computer would be as easy to 
use as my telephone.
My wish has come true.
I no longer know how to use my 
telephone.”

                                                  ­­ Bjarne Stroustrup

      copyright © 2009  cod technologies ltd  www.codtech.com
agenda
●   introduction to android
●   development environment
●   building blocks
●   your first android application
●   testing and performance


             copyright © 2009  cod technologies ltd  www.codtech.com
introduction to android
after this section you will...

                         ●   identify unique features of 
                             android platform
                         ●   compare android against 
                             other platforms
                         ●   understand android building 
                             blocks



              copyright © 2009  cod technologies ltd  www.codtech.com
what is android ?
●   android is the first complete, open 
    and free mobile platform
●   developed by Open Handset 
    Alliance
●   software stack than includes
    –   operating system
    –   middleware
    –   key applications
    –   rich set of APIs                          Portions of this page are reproduced from work created and shared by 
                                                          Google and used according to terms described in the Creative 
                                                                                      Commons 2.5 Attribution License.



                 copyright © 2009  cod technologies ltd  www.codtech.com
is android linux ?
NO, android is not linux !
           android is based on a linux kernel  
                 but it's not GNU/Linux
                             ●   no native windowing 
                                 system
                             ●   no glibc support
                             ●   no GNU/Linux utilities



         copyright © 2009  cod technologies ltd  www.codtech.com
so is android java ?
NO, android is not java !
android is not an implementation 
of any of the Java variants
●   uses the java language
●   implements part of the 
    Java5 SE specification
●   runs on a dalvik virtual 
    machine instead of JVM


              copyright © 2009  cod technologies ltd  www.codtech.com
android linux kernel
android is based on a linux 2.6 kernel, providing
                                  rnel, p
●   security
●   memory management
●   process management
●   network stack
●   driver model
●   abstraction layer
kernel source: source.android.com

                  copyright © 2009  cod technologies ltd  www.codtech.com
linux kernel enhancements
android introduces some linux kernel patches
●   alarm
●   ashmem
●   binder
●   power management
●   low memory killer (no swap space available)
●   logger


                copyright © 2009  cod technologies ltd  www.codtech.com
unique platform characteristics
android characteristics not found on other platforms

●   open source

●   “all applications are equal” model

●   dalvik virtual machine


              copyright © 2009  cod technologies ltd  www.codtech.com
other characteristics
interesting features as well, but they are more 
common across other mobile platforms
●   application framework enabling reuse of components
●   integrated browser based on WebKit OSS engine
●   3D graphics based on the OpenGL ES
●   SQLite for structured data storage
●   media support for common audio, video, and still images
●   camera, GPS, compass, and accelerometer


                 copyright © 2009  cod technologies ltd  www.codtech.com
android architecture



     written in 
      C/C++
                                                                                        written 
                                                                                        in java



                                                                                       register 
                                                                                        based 
                                                                                         VM
courtesy of Google




                             copyright © 2009  cod technologies ltd  www.codtech.com
android development environment
after this section you will...

                         ●   be aware of the components 
                             needed to start developing

                         ●   know the tools available on 
                             the android sdk




              copyright © 2009  cod technologies ltd  www.codtech.com
development environment
ubuntu is the perfect choice
                               ●   supported and tested by 
                                   Google
                               ●   all the necessary tools 
                                   available
                               ●   32bit installation highly 
                                   recommended


         copyright © 2009  cod technologies ltd  www.codtech.com
development environment
Eclipse is an extensible development 
platform
                             ●   much more than an IDE
                             ●   unfortunately no Eclipse 
                                 3.4 packages
                             ●   download from 
                                 http://eclipse.org and 
                                 install
                             ●   android ADT plugin

         copyright © 2009  cod technologies ltd  www.codtech.com
java

●   installed from ubuntu repositories
●   packages matching sun­java6­*

    diego@bruce:~$ java -version
    java version "1.6.0_16"
    Java(TM) SE Runtime Environment (build 1.6.0_16-
    b01)
    Java HotSpot(TM) Client VM (build 14.2-b01, mixed
    mode, sharing)




               copyright © 2009  cod technologies ltd  www.codtech.com
android SDK 1.6 and ADT
●   download from http://developer.android.com 
    and install to /opt directory

●   create symbolic link /opt/android-sdk to 
    point to installed SDK

●   add site 
    https://dl­ssl.google.com/android/eclipse/
    to eclipse software updates for ADT



               copyright © 2009  cod technologies ltd  www.codtech.com
android sdk updater & avd




                         $ android

         copyright © 2009  cod technologies ltd  www.codtech.com
emulator




                  $ emulator @1.5_r3
           copyright © 2009  cod technologies ltd  www.codtech.com
dalvik debug monitor




                             $ ddms
         copyright © 2009  cod technologies ltd  www.codtech.com
zipalign
●   optimizes the way an application is packaged
●   potentially makes your application and system 
    run faster
●   android accesses resources efficiently where 
    they are aligned on 4­byte boundaries
●   ADT automatically align release packages


         $ zipalign -c -v 4 my.apk


              copyright © 2009  cod technologies ltd  www.codtech.com
sqlite database browser




$ sudo apt-get install sqlitebrowser

         copyright © 2009  cod technologies ltd  www.codtech.com
android building blocks
after this section you will...

                            ●   recognize the fundamental 
                                building blocks
                            ●   use these building blocks to 
                                create applications
                            ●   understand applications 
                                lifecycle


             copyright © 2009  cod technologies ltd  www.codtech.com
building blocks




        copyright © 2009  cod technologies ltd  www.codtech.com
Activities

                                       ●   Activities are stacked 
                                           like a deck of cards
                                       ●   only one is visible
                                       ●   only one is active
                                       ●   new activities are 
                                           placed on top



         copyright © 2009  cod technologies ltd  www.codtech.com
Activities lifecycle




rectangles are callbacks where
we can implement operations
performed on state changes


                      copyright © 2009  cod technologies ltd  www.codtech.com
Activities states
●   active
    –   at the top of the stack
●   paused
    –   lost focus but still visible
    –   can be killed by LMK
●   stopped
    –   not at the top of th stack
●   dropped
    –   killed to reclaim its memory

                  copyright © 2009  cod technologies ltd  www.codtech.com
Views

●   Views are basic building blocks

●   know how to draw themselves

●   respond to events

●   organized as trees to build up GUIs

●   described in XML in layout resources


              copyright © 2009  cod technologies ltd  www.codtech.com
Views and Viewgroups
●   Views and 
    Viewgroups trees 
    build up complex 
    GUIs
●   android framework is 
    responsible for
    –   measuring
    –   laying out
    –   drawing


                  copyright © 2009  cod technologies ltd  www.codtech.com
pattern: load layout

android compiles the XML layout code that is 
later loaded in code usually by


                    public void onCreate(Bundle
                    savedInstanceState) {
                       ...
                    setContentView(R.layout.filename);
                       ...
                    }




           copyright © 2009  cod technologies ltd  www.codtech.com
pattern: ids

using an unique id in a XML View definition 
permits locating it later in Java code

                     private View name;

                     public void onCreate(Bundle
                     savedInstanceState) {
                        ...
                        name = (View)
                            findViewById(R.id.name);
                        ...
                     }



            copyright © 2009  cod technologies ltd  www.codtech.com
Intents
●   Intents are used to move from Activity to Activity
●   describes what the application wants
●   provides late runtime binding


    primary attributes
    attribute description
    action   the general action to be performed, such as VIEW,
             EDIT, MAIN, etc.
    data     the data to operate on, such as a person record in
             the contacts database, as URI



                  copyright © 2009  cod technologies ltd  www.codtech.com
intent playground




      install from android market or from
   http://codtech.com/android/IntentPlayground.apk

            copyright © 2009  cod technologies ltd  www.codtech.com
Services
●   services run in the background
●   don't interact with the user
●   run on the main thread
    of the process
●   is kept running as long as
    –   is started
    –   has connections


                     copyright © 2009  cod technologies ltd  www.codtech.com
Notifications

●   notify the user about 
    events
●   sent through 
    NotificationManager
●   types
    –   persistent icon
    –   turning leds
    –   sound or vibration


                 copyright © 2009  cod technologies ltd  www.codtech.com
ConentProviders
●   ContentProviders are objects that can
    –   retrieve data
    –   store data
●   data is available to all applications
●   only way to share data across packages
●   usually the backend is SQLite
●   they are loosely linked to clients
●   data exposed as a unique URI
                 copyright © 2009  cod technologies ltd  www.codtech.com
AndroidManifest.xml
●   control file that tells 
    the system what to do 
    and how the top­level 
    components are 
    related
●   it's the “glue” that 
    actually specifies 
    which Intents your 
    Activities receive
●   specifies permissions
               copyright © 2009  cod technologies ltd  www.codtech.com
your first android application
after this section you will...
                        ●   create your own android map 
                            project
                        ●   design the UI
                        ●   externalize resources
                        ●   react to events
                        ●   run the application


             copyright © 2009  cod technologies ltd  www.codtech.com
designing the UI
                                    this simple UI designs 
                                    contains
                                      ●   the window title
                                      ●   a spinner (drop down 
                                          box) containing the 
                                          available locations
                                      ●   a map displaying the 
                                          selected location
                                      ●   zoom buttons
        copyright © 2009  cod technologies ltd  www.codtech.com
create project



                                                                        android
                                                                         target
                                                                        version
     unique
    package
     name




              copyright © 2009  cod technologies ltd  www.codtech.com
create test project




                                                               test
                                                             package
                                                              name




          copyright © 2009  cod technologies ltd  www.codtech.com
run configurations

if phone is
connected

                                                                        android
                                                                         target
                                                                        version




              copyright © 2009  cod technologies ltd  www.codtech.com
default application
                                       ●   auto­generated 
                                           application template
                                       ●   default resources
                                             –   icon
                                             –   layout
                                             –   strings
                                       ●   default 
                                           AndroidManifest.xml
                                       ●   default run 
                                           configuration
         copyright © 2009  cod technologies ltd  www.codtech.com
create the layout
                                      ●   remove layout
                                      ●   add a RelativeLayout
                                      ●   add a View (MapView not 
                                          supported by ADT)

                                      ●   replace View by 
                                          com.google.android.m
                                          aps.MapView
                                      ●   change id to MapView
                                      ●   add a Spinner filling 
                                          parent width
        copyright © 2009  cod technologies ltd  www.codtech.com
run the application
                                      ●   com.google.android.
                                          maps it's an optional 
                                          library not included by 
                                          default
                                      ●   edit Android Manifest
                                      ●   add Uses Library 
                                          com.google.android.m
                                          aps as Application 
                                          node


        copyright © 2009  cod technologies ltd  www.codtech.com
google maps api key
●   checking DDMS logcat we find
    java.lang.IllegalArgumentException: You need to
    specify an API Key for each MapView.

●   to access Google Maps we need a key
●   application must be signed with the same key
●   key can be obtained from Google
●   MapView should include
    android:apiKey="0GNIO0J9wdmcNm4gCV6S0nlaFE8bHa9W
    XXXXXX"

               copyright © 2009  cod technologies ltd  www.codtech.com
obtaining google maps api key

●   $ keytool -list
    -alias
    androiddebugkey
    -keystore
    ~/.android/debug.k
    eystore
                                                                           your
                                                                        fingerprint
●   http://code.google.co
    m/android/maps­api­
    signup.html


              copyright © 2009  cod technologies ltd  www.codtech.com
MapActivity
●   checking DDMS logcat again

    java.lang.IllegalArgumentException: MapViews can
    only be created inside instances of MapActivity.



●   change base class to MapActivity

●   fix imports

●   add unimplemented methods


                  copyright © 2009  cod technologies ltd  www.codtech.com
where is the map ?
                                      ●   still no map displayed
                                      ●   check DDMS logcat
                                      ●   errors displayed
                                      ●   a permission is missing
                                            –   INTERNET

                                      ●   add it to Manifest


        copyright © 2009  cod technologies ltd  www.codtech.com
finally our map

                                      still some problems ...
                                      ●   spinner is covered
                                           android:layout_alignPa
                                           rentTop="true"


                                      ●   spinner has no prompt
                                           prompt: @string/prompt

                                      ●   externalize resource 
                                          value Select a location

        copyright © 2009  cod technologies ltd  www.codtech.com
pattern: adapters

an Adapter object acts as a bridge between an 
AdapterView and the underlying data for that view

                        ArrayAdapter<CharSequence> adapter =
                           ArrayAdapter.createFromResource(
                             this, R.array.array,
                             android.R.layout.layout);

                        view.setAdapter(adapter);

The Adapter is also responsible for making a View for each item in the 
data set.

                  copyright © 2009  cod technologies ltd  www.codtech.com
pattern: resources

resources are external files (that is, non­code files) 
that are used by your code and compiled into your 
application at build time.

                             <resources>
                                <string-array name=”array”>
                                   <item>item</item>
                                </string-array>
                             </resources>


                         res = getResources().getType(id);




              copyright © 2009  cod technologies ltd  www.codtech.com
locations.xml
    <?xml version="1.0" encoding="UTF-8"?>

    <resources>
    <!-- No support for multidimensional
     arrays or complex objects yet (1.6r1) -->

    <string-array name="location_names">
       <item>Akihabara Convention Hall</item>
       <item>Hotel Villa Fontaine</item>
       <item>Narita Intl. Airport</item>
    </string-array>

    <string-array name="locations">
       <item>35.699434,139.772079,16</item>
       <item>35.669012,139.765384,14</item>
       <item>35.773118,140.379181,12</item>
    </string-array>
    </resources>

        http://android.codtech.com/jls2009/locations.xml
           copyright © 2009  cod technologies ltd  www.codtech.com
complete the class
●   create the locations array field
    locations =
      getResources().getStringArray(R.array.locations);

●   find the views (ids pattern)
     spinner = (Spinner) findViewById(R.id.Spinner01);
     mapView = (MapView) findViewById(R.id.MapView);

●   create the adapter
        final ArrayAdapter<CharSequence> adapter =
        ArrayAdapter.createFromResource(this,
           R.array.location_names,
           android.R.layout.simple_spinner_item);
        spinner.setAdapter(adapter)

                copyright © 2009  cod technologies ltd  www.codtech.com
almost there
                                      ●   map is displayed
                                      ●   spinner is displayed
                                      ●   drop down is 
                                          displayed
                                      ●   but there's no 
                                          selection button ...
                                       adapter.
                                          setDropDownViewResource(
                                             android.R.layout.
                                       simple_spinner_dropdown_item
                                       );



        copyright © 2009  cod technologies ltd  www.codtech.com
respond to events
                                      ●   when an item is 
                                          selected map should 
                                          be centered at that 
                                          location
                                       spinner.
                                          setOnItemSelectedListener(
                                           new
                                       OnItemSelectedListener() {
                                          });


                                      ●   in the listener invoke 
                                          goToSelectedLocation(ar
                                          g2);


        copyright © 2009  cod technologies ltd  www.codtech.com
goToSelectedLocation
   protected void goToSelectedLocation(int position) {
      String[] loc = locations[position].split(",");

       double lat = Double.parseDouble(loc[0]);
       double lon = Double.parseDouble(loc[1]);
       int zoom = Integer.parseInt(loc[2]);

       GeoPoint p = new GeoPoint((int)(lat * 1E6),
          (int)(lon * 1E6));                   mapController 
                                                                           should be 
       Log.d(TAG, "Should go to " + p);                                   initialized in 
                                                                            onCreate
       mapController.animateTo(p);
       mapController.setZoom(zoom);
   }

http://android.codtech.com/jls2009/goToSelectedLocation.txt

                copyright © 2009  cod technologies ltd  www.codtech.com
more events
                                     ●   turn map clickable
                                         android:clickable="true”
                                     ●   override onKeyDown
                                      switch (keyCode) {
                                      case KeyEvent.KEYCODE_I:
                                         mapController.zoomIn();
                                         break;
                                      case KeyEvent.KEYCODE_O:
                                         mapController.zoomOut();
                                         break;
                                      case KeyEvent.KEYCODE_S:
                                         mapView.setSatellite(
                                          !mapView.isSatellite());
                                         break;
                                      }

                                http://android.codtech.com/jls2009/onKeyDown.txt

       copyright © 2009  cod technologies ltd  www.codtech.com
zoom controls
                                     ●   add a FrameLayout
                                     ●   align to parent bottom
                                     ●   in onCreate
                                    ...
                                    zoomControls =
                                        (ViewGroup)findViewById(
                                           R.id.FrameLayout01);

                                    ...                          mapView.setBuiltInZ
                                                                 oomControls(true);

                                    zoomControls.addView(
                                       mapView.getZoomControls());



       copyright © 2009  cod technologies ltd  www.codtech.com
we did it !
●   Some things to try
    –   select a location

    –   pan

    –   zoom in

    –   zoom out

    –   toggle satellite



                   copyright © 2009  cod technologies ltd  www.codtech.com
japanese localization

                          existing
                         resource




                                                                      new 
                                                                   language




         copyright © 2009  cod technologies ltd  www.codtech.com
japanese application


●   resources 
    automatically selected
●   match phone locale
●   no programming 
    needed




              copyright © 2009  cod technologies ltd  www.codtech.com
hierarchyviewer – tree


                                             properties



                                                                      selected
                                                                        view
                                                                     highlighted


selected
  view




           copyright © 2009  cod technologies ltd  www.codtech.com
hierarchyviewer ­ zoom
              selected 
                pixel




                                              pixel
                                              color




        copyright © 2009  cod technologies ltd  www.codtech.com
“Remember that there is no 
 code faster than no code”
        ­­ Taligent's Guide to Designing Programs




    copyright © 2009  cod technologies ltd  www.codtech.com
testing and performance
after this section you will...

                        ●   understand the best practices 
                            to develop for android
                        ●    identify the alternatives to test 
                            units, services and applications
                        ●   performance



             copyright © 2009  cod technologies ltd  www.codtech.com
best practices
●   consider performance, android is not a desktop
●   avoid creating objects
●   use native methods
●   prefer virtual over interface
●   prefer static over virtual (if no object access required)
●   avoid internal getter/setters
●   declares constants final
●   avoid enums

                copyright © 2009  cod technologies ltd  www.codtech.com
testing
●   android sdk 1.6 features
    –   creation of test projects
    –   ActivityUnitTestCase to run isolated unit tests
    –   ServiceTestCase to test services
    –   ActivityInstrumentationTestCase2 to run functional 
        tests of activities
●   ApiDemos includes some test samples
●   monkey, generates pseudo­random of user 
    events
                  copyright © 2009  cod technologies ltd  www.codtech.com
1000000
                                                                                                                                   1500000
                                                                                                                                             2000000
                                                                                                                                                       2500000
                                                                                                                                                                 3000000




                                                                                                                500000



                                                                                                     0
                                                                             Add a local variable


                                                                         Add a member variable


                                                                              Call String.length()


                                                                 Call empty static native method


                                                                       Call empty static method
                                                                                                                                                                           performance




                                                                      Call empty virtual method


                                                                    Call empty interface method


                                                               Call Iterator:next() on a HashMap


                                                                         Call put() on a HashMap


                                                                        Inflate 1 View from XML


                                                          Inflate 1 LinearLayout with 1 TextView

copyright © 2009  cod technologies ltd  www.codtech.com
                                                               Inflate 1 LinearLayout with 6 View


                                                          Inflate 1 LinearLayout with 6 TextView


                                                                       Launch an empty activity
                                                                                                         Time
traceview




    // start tracing to sdcard
    Debug.startMethodTracing(“mytrace”);

            copyright © 2009  cod technologies ltd  www.codtech.com
dmtracedump




     $ sudo apt­get install graphviz
       copyright © 2009  cod technologies ltd  www.codtech.com
“If things seem under control, 
 you're not going fast enough.”
                                                         ­­ Mario Andretti




     copyright © 2009  cod technologies ltd  www.codtech.com
thank you
android development tutorial
                                                              tokyo, october 2009

                                        diego torres milano
                                                   diego@codtech.com

    copyright © 2009  cod technologies ltd  www.codtech.com

More Related Content

What's hot

Introduction to Android - Mobile Fest Singapore 2009
Introduction to Android - Mobile Fest Singapore 2009Introduction to Android - Mobile Fest Singapore 2009
Introduction to Android - Mobile Fest Singapore 2009sullis
 
Being Epic: Best Practices for Android Development
Being Epic: Best Practices for Android DevelopmentBeing Epic: Best Practices for Android Development
Being Epic: Best Practices for Android DevelopmentReto Meier
 
Android dev o_auth
Android dev o_authAndroid dev o_auth
Android dev o_authlzongren
 
Getting started with android dev and test perspective
Getting started with android   dev and test perspectiveGetting started with android   dev and test perspective
Getting started with android dev and test perspectiveGunjan Kumar
 
Android Programming Basics
Android Programming BasicsAndroid Programming Basics
Android Programming BasicsEueung Mulyana
 
9780134433646 annuzzi ch02 (1)
9780134433646 annuzzi ch02 (1)9780134433646 annuzzi ch02 (1)
9780134433646 annuzzi ch02 (1)Peter Mburu
 
Ii 1300-java essentials for android
Ii 1300-java essentials for androidIi 1300-java essentials for android
Ii 1300-java essentials for androidAdrian Mikeliunas
 
Google Glass, the GDK, and HTML5
Google Glass, the GDK, and HTML5Google Glass, the GDK, and HTML5
Google Glass, the GDK, and HTML5Oswald Campesato
 
Android terminologies
Android terminologiesAndroid terminologies
Android terminologiesjerry vasoya
 
Android Programming Basic
Android Programming BasicAndroid Programming Basic
Android Programming BasicDuy Do Phan
 
Day1 before getting_started
Day1 before getting_startedDay1 before getting_started
Day1 before getting_startedAhsanul Karim
 
Embedded Android Workshop at Embedded World Conference 2013
Embedded Android Workshop at Embedded World Conference 2013Embedded Android Workshop at Embedded World Conference 2013
Embedded Android Workshop at Embedded World Conference 2013Opersys inc.
 
Android chapter02-setup2-emulator
Android chapter02-setup2-emulatorAndroid chapter02-setup2-emulator
Android chapter02-setup2-emulatorguru472
 
Google Glasses Integration with SAP
Google Glasses Integration with SAPGoogle Glasses Integration with SAP
Google Glasses Integration with SAPGh14Cc10
 
Embedded Android Workshop / ELC 2013
Embedded Android Workshop / ELC 2013Embedded Android Workshop / ELC 2013
Embedded Android Workshop / ELC 2013Opersys inc.
 
Intel XDK in Brief
Intel XDK in BriefIntel XDK in Brief
Intel XDK in BriefCamilo Corea
 
Rapid mobile development with Ionic framework - Voxxdays Ticino 2015
Rapid mobile development with Ionic framework - Voxxdays Ticino 2015Rapid mobile development with Ionic framework - Voxxdays Ticino 2015
Rapid mobile development with Ionic framework - Voxxdays Ticino 2015Alessio Delmonti
 
Mobile Web Development with HTML5
Mobile Web Development with HTML5Mobile Web Development with HTML5
Mobile Web Development with HTML5Roy Clarkson
 

What's hot (20)

Introduction to Android - Mobile Fest Singapore 2009
Introduction to Android - Mobile Fest Singapore 2009Introduction to Android - Mobile Fest Singapore 2009
Introduction to Android - Mobile Fest Singapore 2009
 
Google Android
Google AndroidGoogle Android
Google Android
 
Being Epic: Best Practices for Android Development
Being Epic: Best Practices for Android DevelopmentBeing Epic: Best Practices for Android Development
Being Epic: Best Practices for Android Development
 
Android dev o_auth
Android dev o_authAndroid dev o_auth
Android dev o_auth
 
Getting started with android dev and test perspective
Getting started with android   dev and test perspectiveGetting started with android   dev and test perspective
Getting started with android dev and test perspective
 
Android Programming Basics
Android Programming BasicsAndroid Programming Basics
Android Programming Basics
 
9780134433646 annuzzi ch02 (1)
9780134433646 annuzzi ch02 (1)9780134433646 annuzzi ch02 (1)
9780134433646 annuzzi ch02 (1)
 
Ii 1300-java essentials for android
Ii 1300-java essentials for androidIi 1300-java essentials for android
Ii 1300-java essentials for android
 
Android Applications Development
Android Applications DevelopmentAndroid Applications Development
Android Applications Development
 
Google Glass, the GDK, and HTML5
Google Glass, the GDK, and HTML5Google Glass, the GDK, and HTML5
Google Glass, the GDK, and HTML5
 
Android terminologies
Android terminologiesAndroid terminologies
Android terminologies
 
Android Programming Basic
Android Programming BasicAndroid Programming Basic
Android Programming Basic
 
Day1 before getting_started
Day1 before getting_startedDay1 before getting_started
Day1 before getting_started
 
Embedded Android Workshop at Embedded World Conference 2013
Embedded Android Workshop at Embedded World Conference 2013Embedded Android Workshop at Embedded World Conference 2013
Embedded Android Workshop at Embedded World Conference 2013
 
Android chapter02-setup2-emulator
Android chapter02-setup2-emulatorAndroid chapter02-setup2-emulator
Android chapter02-setup2-emulator
 
Google Glasses Integration with SAP
Google Glasses Integration with SAPGoogle Glasses Integration with SAP
Google Glasses Integration with SAP
 
Embedded Android Workshop / ELC 2013
Embedded Android Workshop / ELC 2013Embedded Android Workshop / ELC 2013
Embedded Android Workshop / ELC 2013
 
Intel XDK in Brief
Intel XDK in BriefIntel XDK in Brief
Intel XDK in Brief
 
Rapid mobile development with Ionic framework - Voxxdays Ticino 2015
Rapid mobile development with Ionic framework - Voxxdays Ticino 2015Rapid mobile development with Ionic framework - Voxxdays Ticino 2015
Rapid mobile development with Ionic framework - Voxxdays Ticino 2015
 
Mobile Web Development with HTML5
Mobile Web Development with HTML5Mobile Web Development with HTML5
Mobile Web Development with HTML5
 

Viewers also liked

Android Development: The Basics
Android Development: The BasicsAndroid Development: The Basics
Android Development: The BasicsMike Desjardins
 
Mobile Application Development With Android
Mobile Application Development With AndroidMobile Application Development With Android
Mobile Application Development With Androidguest213e237
 
Presentation on Android operating system
Presentation on Android operating systemPresentation on Android operating system
Presentation on Android operating systemSalma Begum
 
Introduction to Android Development: Before Getting Started
Introduction to Android Development: Before Getting StartedIntroduction to Android Development: Before Getting Started
Introduction to Android Development: Before Getting StartedAhsanul Karim
 
Android Development - NOTE TAKING APP FROM SCRATCH
Android Development - NOTE TAKING APP FROM SCRATCHAndroid Development - NOTE TAKING APP FROM SCRATCH
Android Development - NOTE TAKING APP FROM SCRATCHKeith Levi Lumanog
 
Android presentation
Android presentationAndroid presentation
Android presentationElyes Naouar
 
Intoduction to Network Security NS1
Intoduction to Network Security NS1Intoduction to Network Security NS1
Intoduction to Network Security NS1koolkampus
 
CITY OF SPIES BY SORAYYA KHAN
CITY OF SPIES BY SORAYYA KHANCITY OF SPIES BY SORAYYA KHAN
CITY OF SPIES BY SORAYYA KHANSheikh Hasnain
 
ICCV2009: MAP Inference in Discrete Models: Part 5
ICCV2009: MAP Inference in Discrete Models: Part 5ICCV2009: MAP Inference in Discrete Models: Part 5
ICCV2009: MAP Inference in Discrete Models: Part 5zukun
 
Functional programming with python
Functional programming with pythonFunctional programming with python
Functional programming with pythonMarcelo Cure
 
Android Application: Introduction
Android Application: IntroductionAndroid Application: Introduction
Android Application: IntroductionJollen Chen
 

Viewers also liked (20)

Android workShop
Android workShopAndroid workShop
Android workShop
 
Android Development: The Basics
Android Development: The BasicsAndroid Development: The Basics
Android Development: The Basics
 
Mobile Application Development With Android
Mobile Application Development With AndroidMobile Application Development With Android
Mobile Application Development With Android
 
Android ppt
Android pptAndroid ppt
Android ppt
 
Presentation on Android operating system
Presentation on Android operating systemPresentation on Android operating system
Presentation on Android operating system
 
Android ppt
Android ppt Android ppt
Android ppt
 
z/OS V2R2 Enhancements
z/OS V2R2 Enhancementsz/OS V2R2 Enhancements
z/OS V2R2 Enhancements
 
Introduction to Android Development: Before Getting Started
Introduction to Android Development: Before Getting StartedIntroduction to Android Development: Before Getting Started
Introduction to Android Development: Before Getting Started
 
Android Development - NOTE TAKING APP FROM SCRATCH
Android Development - NOTE TAKING APP FROM SCRATCHAndroid Development - NOTE TAKING APP FROM SCRATCH
Android Development - NOTE TAKING APP FROM SCRATCH
 
Android presentation
Android presentationAndroid presentation
Android presentation
 
Trends in spies
Trends in spiesTrends in spies
Trends in spies
 
Intoduction to Network Security NS1
Intoduction to Network Security NS1Intoduction to Network Security NS1
Intoduction to Network Security NS1
 
Functional style programming
Functional style programmingFunctional style programming
Functional style programming
 
CITY OF SPIES BY SORAYYA KHAN
CITY OF SPIES BY SORAYYA KHANCITY OF SPIES BY SORAYYA KHAN
CITY OF SPIES BY SORAYYA KHAN
 
Lec 03 set
Lec 03   setLec 03   set
Lec 03 set
 
ICCV2009: MAP Inference in Discrete Models: Part 5
ICCV2009: MAP Inference in Discrete Models: Part 5ICCV2009: MAP Inference in Discrete Models: Part 5
ICCV2009: MAP Inference in Discrete Models: Part 5
 
Functional programming with python
Functional programming with pythonFunctional programming with python
Functional programming with python
 
SAN Review
SAN ReviewSAN Review
SAN Review
 
Android Application: Introduction
Android Application: IntroductionAndroid Application: Introduction
Android Application: Introduction
 
Securing Windows web servers
Securing Windows web serversSecuring Windows web servers
Securing Windows web servers
 

Similar to Android Development Tutorial V3

Is Android the New King of Embedded OSes at Embedded World 2014
Is Android the New King of Embedded OSes at Embedded World 2014Is Android the New King of Embedded OSes at Embedded World 2014
Is Android the New King of Embedded OSes at Embedded World 2014Opersys inc.
 
Is Android the New Embedded Linux? at AnDevCon IV
Is Android the New Embedded Linux? at AnDevCon IVIs Android the New Embedded Linux? at AnDevCon IV
Is Android the New Embedded Linux? at AnDevCon IVOpersys inc.
 
Embedded Android Workshop with Nougat
Embedded Android Workshop with NougatEmbedded Android Workshop with Nougat
Embedded Android Workshop with NougatOpersys inc.
 
Is Android the New Embedded Linux? at AnDevCon VI
Is Android the New Embedded Linux? at AnDevCon VIIs Android the New Embedded Linux? at AnDevCon VI
Is Android the New Embedded Linux? at AnDevCon VIOpersys inc.
 
Is Android the New Embedded Linux? at AnDevCon V
Is Android the New Embedded Linux? at AnDevCon VIs Android the New Embedded Linux? at AnDevCon V
Is Android the New Embedded Linux? at AnDevCon VOpersys inc.
 
Embedded Android Workshop at AnDevCon IV
Embedded Android Workshop at AnDevCon IVEmbedded Android Workshop at AnDevCon IV
Embedded Android Workshop at AnDevCon IVOpersys inc.
 
Why Users Are Moving on from Docker and Leaving Its Security Risks Behind (Sp...
Why Users Are Moving on from Docker and Leaving Its Security Risks Behind (Sp...Why Users Are Moving on from Docker and Leaving Its Security Risks Behind (Sp...
Why Users Are Moving on from Docker and Leaving Its Security Risks Behind (Sp...Amazon Web Services
 
Embedded Android Workshop at ABS 2014
Embedded Android Workshop at ABS 2014Embedded Android Workshop at ABS 2014
Embedded Android Workshop at ABS 2014Opersys inc.
 
Embedded Android Workshop
Embedded Android WorkshopEmbedded Android Workshop
Embedded Android WorkshopOpersys inc.
 
Embedded Android Workshop
Embedded Android WorkshopEmbedded Android Workshop
Embedded Android WorkshopOpersys inc.
 
Embedded Android Workshop at AnDevCon V
Embedded Android Workshop at AnDevCon VEmbedded Android Workshop at AnDevCon V
Embedded Android Workshop at AnDevCon VOpersys inc.
 
Embedded Android Workshop
Embedded Android WorkshopEmbedded Android Workshop
Embedded Android WorkshopOpersys inc.
 
Embedded Android Workshop with Oreo
Embedded Android Workshop with OreoEmbedded Android Workshop with Oreo
Embedded Android Workshop with OreoOpersys inc.
 
Android As a Server- Building Android for the Cloud (AnDevCon SF 2013)
Android As a Server- Building Android for the Cloud (AnDevCon SF 2013)Android As a Server- Building Android for the Cloud (AnDevCon SF 2013)
Android As a Server- Building Android for the Cloud (AnDevCon SF 2013)Ron Munitz
 
Embedded Android Workshop at Embedded World 2014
Embedded Android Workshop at Embedded World 2014Embedded Android Workshop at Embedded World 2014
Embedded Android Workshop at Embedded World 2014Opersys inc.
 
Android Jumpstart ESC SV 2012 Part I
Android Jumpstart ESC SV 2012 Part IAndroid Jumpstart ESC SV 2012 Part I
Android Jumpstart ESC SV 2012 Part IOpersys inc.
 
Embedded Android Workshop at AnDevCon VI
Embedded Android Workshop at AnDevCon VIEmbedded Android Workshop at AnDevCon VI
Embedded Android Workshop at AnDevCon VIOpersys inc.
 
Embedded Android Workshop at ELC Europe
Embedded Android Workshop at ELC EuropeEmbedded Android Workshop at ELC Europe
Embedded Android Workshop at ELC EuropeOpersys inc.
 
Embedded Android Workshop with Marshmallow
Embedded Android Workshop with MarshmallowEmbedded Android Workshop with Marshmallow
Embedded Android Workshop with MarshmallowKarim Yaghmour
 

Similar to Android Development Tutorial V3 (20)

Is Android the New King of Embedded OSes at Embedded World 2014
Is Android the New King of Embedded OSes at Embedded World 2014Is Android the New King of Embedded OSes at Embedded World 2014
Is Android the New King of Embedded OSes at Embedded World 2014
 
Is Android the New Embedded Linux? at AnDevCon IV
Is Android the New Embedded Linux? at AnDevCon IVIs Android the New Embedded Linux? at AnDevCon IV
Is Android the New Embedded Linux? at AnDevCon IV
 
Gl android platform
Gl android platformGl android platform
Gl android platform
 
Embedded Android Workshop with Nougat
Embedded Android Workshop with NougatEmbedded Android Workshop with Nougat
Embedded Android Workshop with Nougat
 
Is Android the New Embedded Linux? at AnDevCon VI
Is Android the New Embedded Linux? at AnDevCon VIIs Android the New Embedded Linux? at AnDevCon VI
Is Android the New Embedded Linux? at AnDevCon VI
 
Is Android the New Embedded Linux? at AnDevCon V
Is Android the New Embedded Linux? at AnDevCon VIs Android the New Embedded Linux? at AnDevCon V
Is Android the New Embedded Linux? at AnDevCon V
 
Embedded Android Workshop at AnDevCon IV
Embedded Android Workshop at AnDevCon IVEmbedded Android Workshop at AnDevCon IV
Embedded Android Workshop at AnDevCon IV
 
Why Users Are Moving on from Docker and Leaving Its Security Risks Behind (Sp...
Why Users Are Moving on from Docker and Leaving Its Security Risks Behind (Sp...Why Users Are Moving on from Docker and Leaving Its Security Risks Behind (Sp...
Why Users Are Moving on from Docker and Leaving Its Security Risks Behind (Sp...
 
Embedded Android Workshop at ABS 2014
Embedded Android Workshop at ABS 2014Embedded Android Workshop at ABS 2014
Embedded Android Workshop at ABS 2014
 
Embedded Android Workshop
Embedded Android WorkshopEmbedded Android Workshop
Embedded Android Workshop
 
Embedded Android Workshop
Embedded Android WorkshopEmbedded Android Workshop
Embedded Android Workshop
 
Embedded Android Workshop at AnDevCon V
Embedded Android Workshop at AnDevCon VEmbedded Android Workshop at AnDevCon V
Embedded Android Workshop at AnDevCon V
 
Embedded Android Workshop
Embedded Android WorkshopEmbedded Android Workshop
Embedded Android Workshop
 
Embedded Android Workshop with Oreo
Embedded Android Workshop with OreoEmbedded Android Workshop with Oreo
Embedded Android Workshop with Oreo
 
Android As a Server- Building Android for the Cloud (AnDevCon SF 2013)
Android As a Server- Building Android for the Cloud (AnDevCon SF 2013)Android As a Server- Building Android for the Cloud (AnDevCon SF 2013)
Android As a Server- Building Android for the Cloud (AnDevCon SF 2013)
 
Embedded Android Workshop at Embedded World 2014
Embedded Android Workshop at Embedded World 2014Embedded Android Workshop at Embedded World 2014
Embedded Android Workshop at Embedded World 2014
 
Android Jumpstart ESC SV 2012 Part I
Android Jumpstart ESC SV 2012 Part IAndroid Jumpstart ESC SV 2012 Part I
Android Jumpstart ESC SV 2012 Part I
 
Embedded Android Workshop at AnDevCon VI
Embedded Android Workshop at AnDevCon VIEmbedded Android Workshop at AnDevCon VI
Embedded Android Workshop at AnDevCon VI
 
Embedded Android Workshop at ELC Europe
Embedded Android Workshop at ELC EuropeEmbedded Android Workshop at ELC Europe
Embedded Android Workshop at ELC Europe
 
Embedded Android Workshop with Marshmallow
Embedded Android Workshop with MarshmallowEmbedded Android Workshop with Marshmallow
Embedded Android Workshop with Marshmallow
 

Android Development Tutorial V3

  • 1. japan linux symposium android development tutorial tokyo, october 2009 diego torres milano diego@codtech.com copyright © 2009  cod technologies ltd  www.codtech.com
  • 3. agenda ● introduction to android ● development environment ● building blocks ● your first android application ● testing and performance copyright © 2009  cod technologies ltd  www.codtech.com
  • 4. introduction to android after this section you will... ● identify unique features of  android platform ● compare android against  other platforms ● understand android building  blocks copyright © 2009  cod technologies ltd  www.codtech.com
  • 5. what is android ? ● android is the first complete, open  and free mobile platform ● developed by Open Handset  Alliance ● software stack than includes – operating system – middleware – key applications – rich set of APIs Portions of this page are reproduced from work created and shared by  Google and used according to terms described in the Creative  Commons 2.5 Attribution License. copyright © 2009  cod technologies ltd  www.codtech.com
  • 6. is android linux ? NO, android is not linux ! android is based on a linux kernel   but it's not GNU/Linux ● no native windowing  system ● no glibc support ● no GNU/Linux utilities copyright © 2009  cod technologies ltd  www.codtech.com
  • 7. so is android java ? NO, android is not java ! android is not an implementation  of any of the Java variants ● uses the java language ● implements part of the  Java5 SE specification ● runs on a dalvik virtual  machine instead of JVM copyright © 2009  cod technologies ltd  www.codtech.com
  • 8. android linux kernel android is based on a linux 2.6 kernel, providing rnel, p ● security ● memory management ● process management ● network stack ● driver model ● abstraction layer kernel source: source.android.com copyright © 2009  cod technologies ltd  www.codtech.com
  • 9. linux kernel enhancements android introduces some linux kernel patches ● alarm ● ashmem ● binder ● power management ● low memory killer (no swap space available) ● logger copyright © 2009  cod technologies ltd  www.codtech.com
  • 10. unique platform characteristics android characteristics not found on other platforms ● open source ● “all applications are equal” model ● dalvik virtual machine copyright © 2009  cod technologies ltd  www.codtech.com
  • 11. other characteristics interesting features as well, but they are more  common across other mobile platforms ● application framework enabling reuse of components ● integrated browser based on WebKit OSS engine ● 3D graphics based on the OpenGL ES ● SQLite for structured data storage ● media support for common audio, video, and still images ● camera, GPS, compass, and accelerometer copyright © 2009  cod technologies ltd  www.codtech.com
  • 12. android architecture written in  C/C++ written  in java register  based  VM courtesy of Google copyright © 2009  cod technologies ltd  www.codtech.com
  • 13. android development environment after this section you will... ● be aware of the components  needed to start developing ● know the tools available on  the android sdk copyright © 2009  cod technologies ltd  www.codtech.com
  • 14. development environment ubuntu is the perfect choice ● supported and tested by  Google ● all the necessary tools  available ● 32bit installation highly  recommended copyright © 2009  cod technologies ltd  www.codtech.com
  • 15. development environment Eclipse is an extensible development  platform ● much more than an IDE ● unfortunately no Eclipse  3.4 packages ● download from  http://eclipse.org and  install ● android ADT plugin copyright © 2009  cod technologies ltd  www.codtech.com
  • 16. java ● installed from ubuntu repositories ● packages matching sun­java6­* diego@bruce:~$ java -version java version "1.6.0_16" Java(TM) SE Runtime Environment (build 1.6.0_16- b01) Java HotSpot(TM) Client VM (build 14.2-b01, mixed mode, sharing) copyright © 2009  cod technologies ltd  www.codtech.com
  • 17. android SDK 1.6 and ADT ● download from http://developer.android.com  and install to /opt directory ● create symbolic link /opt/android-sdk to  point to installed SDK ● add site  https://dl­ssl.google.com/android/eclipse/ to eclipse software updates for ADT copyright © 2009  cod technologies ltd  www.codtech.com
  • 18. android sdk updater & avd $ android copyright © 2009  cod technologies ltd  www.codtech.com
  • 19. emulator $ emulator @1.5_r3 copyright © 2009  cod technologies ltd  www.codtech.com
  • 20. dalvik debug monitor $ ddms copyright © 2009  cod technologies ltd  www.codtech.com
  • 21. zipalign ● optimizes the way an application is packaged ● potentially makes your application and system  run faster ● android accesses resources efficiently where  they are aligned on 4­byte boundaries ● ADT automatically align release packages $ zipalign -c -v 4 my.apk copyright © 2009  cod technologies ltd  www.codtech.com
  • 22. sqlite database browser $ sudo apt-get install sqlitebrowser copyright © 2009  cod technologies ltd  www.codtech.com
  • 23. android building blocks after this section you will... ● recognize the fundamental  building blocks ● use these building blocks to  create applications ● understand applications  lifecycle copyright © 2009  cod technologies ltd  www.codtech.com
  • 24. building blocks copyright © 2009  cod technologies ltd  www.codtech.com
  • 25. Activities ● Activities are stacked  like a deck of cards ● only one is visible ● only one is active ● new activities are  placed on top copyright © 2009  cod technologies ltd  www.codtech.com
  • 27. Activities states ● active – at the top of the stack ● paused – lost focus but still visible – can be killed by LMK ● stopped – not at the top of th stack ● dropped – killed to reclaim its memory copyright © 2009  cod technologies ltd  www.codtech.com
  • 28. Views ● Views are basic building blocks ● know how to draw themselves ● respond to events ● organized as trees to build up GUIs ● described in XML in layout resources copyright © 2009  cod technologies ltd  www.codtech.com
  • 29. Views and Viewgroups ● Views and  Viewgroups trees  build up complex  GUIs ● android framework is  responsible for – measuring – laying out – drawing copyright © 2009  cod technologies ltd  www.codtech.com
  • 30. pattern: load layout android compiles the XML layout code that is  later loaded in code usually by public void onCreate(Bundle savedInstanceState) { ... setContentView(R.layout.filename); ... } copyright © 2009  cod technologies ltd  www.codtech.com
  • 31. pattern: ids using an unique id in a XML View definition  permits locating it later in Java code private View name; public void onCreate(Bundle savedInstanceState) { ... name = (View) findViewById(R.id.name); ... } copyright © 2009  cod technologies ltd  www.codtech.com
  • 32. Intents ● Intents are used to move from Activity to Activity ● describes what the application wants ● provides late runtime binding primary attributes attribute description action the general action to be performed, such as VIEW, EDIT, MAIN, etc. data the data to operate on, such as a person record in the contacts database, as URI copyright © 2009  cod technologies ltd  www.codtech.com
  • 33. intent playground install from android market or from http://codtech.com/android/IntentPlayground.apk copyright © 2009  cod technologies ltd  www.codtech.com
  • 34. Services ● services run in the background ● don't interact with the user ● run on the main thread of the process ● is kept running as long as – is started – has connections copyright © 2009  cod technologies ltd  www.codtech.com
  • 35. Notifications ● notify the user about  events ● sent through  NotificationManager ● types – persistent icon – turning leds – sound or vibration copyright © 2009  cod technologies ltd  www.codtech.com
  • 36. ConentProviders ● ContentProviders are objects that can – retrieve data – store data ● data is available to all applications ● only way to share data across packages ● usually the backend is SQLite ● they are loosely linked to clients ● data exposed as a unique URI copyright © 2009  cod technologies ltd  www.codtech.com
  • 37. AndroidManifest.xml ● control file that tells  the system what to do  and how the top­level  components are  related ● it's the “glue” that  actually specifies  which Intents your  Activities receive ● specifies permissions copyright © 2009  cod technologies ltd  www.codtech.com
  • 38. your first android application after this section you will... ● create your own android map  project ● design the UI ● externalize resources ● react to events ● run the application copyright © 2009  cod technologies ltd  www.codtech.com
  • 39. designing the UI this simple UI designs  contains ● the window title ● a spinner (drop down  box) containing the  available locations ● a map displaying the  selected location ● zoom buttons copyright © 2009  cod technologies ltd  www.codtech.com
  • 40. create project android target version unique package name copyright © 2009  cod technologies ltd  www.codtech.com
  • 41. create test project test package name copyright © 2009  cod technologies ltd  www.codtech.com
  • 42. run configurations if phone is connected android target version copyright © 2009  cod technologies ltd  www.codtech.com
  • 43. default application ● auto­generated  application template ● default resources – icon – layout – strings ● default  AndroidManifest.xml ● default run  configuration copyright © 2009  cod technologies ltd  www.codtech.com
  • 44. create the layout ● remove layout ● add a RelativeLayout ● add a View (MapView not  supported by ADT) ● replace View by  com.google.android.m aps.MapView ● change id to MapView ● add a Spinner filling  parent width copyright © 2009  cod technologies ltd  www.codtech.com
  • 45. run the application ● com.google.android. maps it's an optional  library not included by  default ● edit Android Manifest ● add Uses Library  com.google.android.m aps as Application  node copyright © 2009  cod technologies ltd  www.codtech.com
  • 46. google maps api key ● checking DDMS logcat we find java.lang.IllegalArgumentException: You need to specify an API Key for each MapView. ● to access Google Maps we need a key ● application must be signed with the same key ● key can be obtained from Google ● MapView should include android:apiKey="0GNIO0J9wdmcNm4gCV6S0nlaFE8bHa9W XXXXXX" copyright © 2009  cod technologies ltd  www.codtech.com
  • 47. obtaining google maps api key ● $ keytool -list -alias androiddebugkey -keystore ~/.android/debug.k eystore your fingerprint ● http://code.google.co m/android/maps­api­ signup.html copyright © 2009  cod technologies ltd  www.codtech.com
  • 48. MapActivity ● checking DDMS logcat again java.lang.IllegalArgumentException: MapViews can only be created inside instances of MapActivity. ● change base class to MapActivity ● fix imports ● add unimplemented methods copyright © 2009  cod technologies ltd  www.codtech.com
  • 49. where is the map ? ● still no map displayed ● check DDMS logcat ● errors displayed ● a permission is missing – INTERNET ● add it to Manifest copyright © 2009  cod technologies ltd  www.codtech.com
  • 50. finally our map still some problems ... ● spinner is covered android:layout_alignPa rentTop="true" ● spinner has no prompt prompt: @string/prompt ● externalize resource  value Select a location copyright © 2009  cod technologies ltd  www.codtech.com
  • 51. pattern: adapters an Adapter object acts as a bridge between an  AdapterView and the underlying data for that view ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource( this, R.array.array, android.R.layout.layout); view.setAdapter(adapter); The Adapter is also responsible for making a View for each item in the  data set. copyright © 2009  cod technologies ltd  www.codtech.com
  • 52. pattern: resources resources are external files (that is, non­code files)  that are used by your code and compiled into your  application at build time. <resources> <string-array name=”array”> <item>item</item> </string-array> </resources> res = getResources().getType(id); copyright © 2009  cod technologies ltd  www.codtech.com
  • 53. locations.xml <?xml version="1.0" encoding="UTF-8"?> <resources> <!-- No support for multidimensional arrays or complex objects yet (1.6r1) --> <string-array name="location_names"> <item>Akihabara Convention Hall</item> <item>Hotel Villa Fontaine</item> <item>Narita Intl. Airport</item> </string-array> <string-array name="locations"> <item>35.699434,139.772079,16</item> <item>35.669012,139.765384,14</item> <item>35.773118,140.379181,12</item> </string-array> </resources> http://android.codtech.com/jls2009/locations.xml copyright © 2009  cod technologies ltd  www.codtech.com
  • 54. complete the class ● create the locations array field locations = getResources().getStringArray(R.array.locations); ● find the views (ids pattern) spinner = (Spinner) findViewById(R.id.Spinner01); mapView = (MapView) findViewById(R.id.MapView); ● create the adapter final ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.location_names, android.R.layout.simple_spinner_item); spinner.setAdapter(adapter) copyright © 2009  cod technologies ltd  www.codtech.com
  • 55. almost there ● map is displayed ● spinner is displayed ● drop down is  displayed ● but there's no  selection button ... adapter. setDropDownViewResource( android.R.layout. simple_spinner_dropdown_item ); copyright © 2009  cod technologies ltd  www.codtech.com
  • 56. respond to events ● when an item is  selected map should  be centered at that  location spinner. setOnItemSelectedListener( new OnItemSelectedListener() { }); ● in the listener invoke  goToSelectedLocation(ar g2); copyright © 2009  cod technologies ltd  www.codtech.com
  • 57. goToSelectedLocation protected void goToSelectedLocation(int position) { String[] loc = locations[position].split(","); double lat = Double.parseDouble(loc[0]); double lon = Double.parseDouble(loc[1]); int zoom = Integer.parseInt(loc[2]); GeoPoint p = new GeoPoint((int)(lat * 1E6), (int)(lon * 1E6)); mapController  should be  Log.d(TAG, "Should go to " + p); initialized in  onCreate mapController.animateTo(p); mapController.setZoom(zoom); } http://android.codtech.com/jls2009/goToSelectedLocation.txt copyright © 2009  cod technologies ltd  www.codtech.com
  • 58. more events ● turn map clickable android:clickable="true” ● override onKeyDown switch (keyCode) { case KeyEvent.KEYCODE_I: mapController.zoomIn(); break; case KeyEvent.KEYCODE_O: mapController.zoomOut(); break; case KeyEvent.KEYCODE_S: mapView.setSatellite( !mapView.isSatellite()); break; } http://android.codtech.com/jls2009/onKeyDown.txt copyright © 2009  cod technologies ltd  www.codtech.com
  • 59. zoom controls ● add a FrameLayout ● align to parent bottom ● in onCreate ... zoomControls = (ViewGroup)findViewById( R.id.FrameLayout01); ... mapView.setBuiltInZ oomControls(true); zoomControls.addView( mapView.getZoomControls()); copyright © 2009  cod technologies ltd  www.codtech.com
  • 60. we did it ! ● Some things to try – select a location – pan – zoom in – zoom out – toggle satellite copyright © 2009  cod technologies ltd  www.codtech.com
  • 61. japanese localization existing resource new  language copyright © 2009  cod technologies ltd  www.codtech.com
  • 62. japanese application ● resources  automatically selected ● match phone locale ● no programming  needed copyright © 2009  cod technologies ltd  www.codtech.com
  • 63. hierarchyviewer – tree properties selected view highlighted selected view copyright © 2009  cod technologies ltd  www.codtech.com
  • 64. hierarchyviewer ­ zoom selected  pixel pixel color copyright © 2009  cod technologies ltd  www.codtech.com
  • 65. “Remember that there is no  code faster than no code” ­­ Taligent's Guide to Designing Programs copyright © 2009  cod technologies ltd  www.codtech.com
  • 66. testing and performance after this section you will... ● understand the best practices  to develop for android ●  identify the alternatives to test  units, services and applications ● performance copyright © 2009  cod technologies ltd  www.codtech.com
  • 67. best practices ● consider performance, android is not a desktop ● avoid creating objects ● use native methods ● prefer virtual over interface ● prefer static over virtual (if no object access required) ● avoid internal getter/setters ● declares constants final ● avoid enums copyright © 2009  cod technologies ltd  www.codtech.com
  • 68. testing ● android sdk 1.6 features – creation of test projects – ActivityUnitTestCase to run isolated unit tests – ServiceTestCase to test services – ActivityInstrumentationTestCase2 to run functional  tests of activities ● ApiDemos includes some test samples ● monkey, generates pseudo­random of user  events copyright © 2009  cod technologies ltd  www.codtech.com
  • 69. 1000000 1500000 2000000 2500000 3000000 500000 0 Add a local variable Add a member variable Call String.length() Call empty static native method Call empty static method performance Call empty virtual method Call empty interface method Call Iterator:next() on a HashMap Call put() on a HashMap Inflate 1 View from XML Inflate 1 LinearLayout with 1 TextView copyright © 2009  cod technologies ltd  www.codtech.com Inflate 1 LinearLayout with 6 View Inflate 1 LinearLayout with 6 TextView Launch an empty activity Time
  • 70. traceview // start tracing to sdcard Debug.startMethodTracing(“mytrace”); copyright © 2009  cod technologies ltd  www.codtech.com
  • 71. dmtracedump $ sudo apt­get install graphviz copyright © 2009  cod technologies ltd  www.codtech.com
  • 72. “If things seem under control,  you're not going fast enough.” ­­ Mario Andretti copyright © 2009  cod technologies ltd  www.codtech.com
  • 73. thank you android development tutorial tokyo, october 2009 diego torres milano diego@codtech.com copyright © 2009  cod technologies ltd  www.codtech.com