#MobileDevDay: A crash course in Android Development

Embed Size (px)

Citation preview

  • 8/4/2019 #MobileDevDay: A crash course in Android Development

    1/29

    Android in 60 minutes

    By Yap Wen Jiun @wenjiun

    Multimedia University Lecturer

    CodeAndroid Malaysia Co-founder

  • 8/4/2019 #MobileDevDay: A crash course in Android Development

    2/29

    What is Android?Android is a software stack for mobile devices

    that includes:

    operating system

    middleware

    key applications http://www.android.com/

  • 8/4/2019 #MobileDevDay: A crash course in Android Development

    3/29

    http://developer.android.com/guide/basics/what-is-android.html

  • 8/4/2019 #MobileDevDay: A crash course in Android Development

    4/29

    Java & AndroidAndroid Apps are written usingJava

    Android runtime core libraries are a large

    subset of Apache Harmony open source Java SE

    libraries

    Dalvik Virtual Machine is a Java VM optimized

    for mobile that runs Dalvik Executables (.dex)which is converted from multiple .class files

  • 8/4/2019 #MobileDevDay: A crash course in Android Development

    5/29

    Development EnviromentAndroid SDK provides APIs & tools

    http://developer.android.com/sdk

    Recommended IDE Eclipse (3.5, 3.6 or 3.7)

    requiresJDK 5 or 6

    Bind the Android SDK to Eclipse with AndroidDevelopment Tools (ADT) plugin

  • 8/4/2019 #MobileDevDay: A crash course in Android Development

    6/29

    Android SDK

    Updated with Android SDK & AVD Manager

    In the SDK:

    Core Libraries android.jar

    Emulator Android Virtual Device (AVD)

    Documentation & Sample Codes

    Tools ADB, DDMS, draw9patch, ProGuard,

    HierarchyViewer, SQLite3 etc.

  • 8/4/2019 #MobileDevDay: A crash course in Android Development

    7/29

    Android VersionVersion Nickname API Level Core Libraries size

    1.5 Cupcake 3 3.0MB

    1.6 Donut 4 3.1MB

    2.1 Eclair 7 4.9MB

    2.2 Froyo 8 5.2MB

    2.3 2.3.2 Gingerbread 9 8.0MB

    2.3.3 2.3.4 Gingerbread 10 9.5MB

    3.0 Honeycomb 11 12.2MB

    3.1 Honeycomb 12 12.4MB3.2 Honeycomb 13 12.8MB

  • 8/4/2019 #MobileDevDay: A crash course in Android Development

    8/29

    Android Version

    http://developer.android.com/resources/dashboard/platform-versions.html

    (as of 2 Sep 2011)

    http://developer.android.com/resources/dashboard/platform-versions.htmlhttp://developer.android.com/resources/dashboard/platform-versions.html
  • 8/4/2019 #MobileDevDay: A crash course in Android Development

    9/29

    Android Virtual Device

    Emulator to test Android Apps

    Created with Android SDK & AVD Manager

    Different Android API level

    Whether to support Google APIs

    Screen resolution & sizeSD Card support and its size

  • 8/4/2019 #MobileDevDay: A crash course in Android Development

    10/29

    Testing on Hardware

    Windows PC requires USB driver

    Linux PC requires UDEV rules file

    Connect to PC with Android Debug Bridge (adb)

    or Dalvik Debug Monitor Service (DDMS) similar

    to AVDs

  • 8/4/2019 #MobileDevDay: A crash course in Android Development

    11/29

    Hello World

    The default new Android project

    Build Target not required to be the latest API

    level, just enough for the features required

    Minimum SDK Version usually lower than Build

    Target to support more users with older devices Package name is the unique identifier

  • 8/4/2019 #MobileDevDay: A crash course in Android Development

    12/29

    What is Activity?The user interface screen

    Implemented as a subclass derived from the

    Activity base class

    1 of the 4 Android Application Components

    Each Activity is given a default window and the

    visual content is provided by a hierarchy of

    Views

  • 8/4/2019 #MobileDevDay: A crash course in Android Development

    13/29

    Activity Lifecycle

  • 8/4/2019 #MobileDevDay: A crash course in Android Development

    14/29

    Project Structure

    src/ : Java source (*.java)

    res/ : resources such as XML files, images

    assets/ : assets, self-managed resources

    bin/ : compiled binaries (*.apk)

    gen/ : auto-generated (R.java)

    libs/ : 3rd party Java libraries (*.jar)

    AndroidManifest.xml

  • 8/4/2019 #MobileDevDay: A crash course in Android Development

    15/29

    Android ManifestProvides essential info such as

    VersionCode for Apps updates

    Components such as Activity are mandatory to

    be declared

    Permissions for inccurring cost, accesing

    certain hardware or private dataEdited in various tabs within Android Manifest

    Editor

  • 8/4/2019 #MobileDevDay: A crash course in Android Development

    16/29

    XML-based Layout

    A specification of visual placements or

    relationships for UI Widgets and Containers

    Edited using Graphical Layout Editor

    Stored in res/layout/

    Attached in setContentView() in Activity's

    onCreate() callback

  • 8/4/2019 #MobileDevDay: A crash course in Android Development

    17/29

    UI Widgets

    Typical elements of Android GUI toolkit

    TextView for text labels

    Button for interactions

    EditText for text inputs

    ImageView for displaying images

    CheckBox for selections between 2 states

  • 8/4/2019 #MobileDevDay: A crash course in Android Development

    18/29

    Identification in Layout XML

    UI Widgets or Containers in layout XML that

    need to be used in the Java source are identifiedby an ID with android:id="@+id/widgetID"

    Java source access the identified widgets with

    findViewById()

  • 8/4/2019 #MobileDevDay: A crash course in Android Development

    19/29

    Arrangment with Containers

    The parent elements to place the UI Widgets

    Lined up vertically or horizontally 1 by 1 in

    LinearLayout Widgets are placed based on relationship with

    others in RelativeLayout

    Widgets are placed in a grid in TableLayout via

    TableRow

  • 8/4/2019 #MobileDevDay: A crash course in Android Development

    20/29

    Handling UI Events

    Using Event Listeners interface such as

    OnClickListener(), OnCheckedChangeListener()

    Register Event Listeners to UI Widgets or Activity

    using methods such as setOnClickListener()

    Event Listeners include callback methods such as

    onClick() for OnClickListener()

  • 8/4/2019 #MobileDevDay: A crash course in Android Development

    21/29

    What is Intent?

    Message that declares the intention to perform

    an action, usually with a piece ofdata

    Intents are passed to startActivity( ) to launch an

    activity

    Activity using Intent Filters to be notified by

    Intents

  • 8/4/2019 #MobileDevDay: A crash course in Android Development

    22/29

    Launching Activity

    Explicit Intent Start a new activity explicitly

    by specifying the class

    Used in multiple screens AppsImplicit Intent Start a new activity implicitly

    by requesting an action be performed on a data

    Useful for browsing, sharing, opening map ...

  • 8/4/2019 #MobileDevDay: A crash course in Android Development

    23/29

    Launching Sub-Activity

    startActivityForResult( ) launches an activity as

    a sub-activity

    Useful in taking photo, scanning barcode

    Sub-activity calls setResult() to return a result

    to the parent activity and triggers an event

    handler onActivityResult() within the parent

    activity when it closes

  • 8/4/2019 #MobileDevDay: A crash course in Android Development

    24/29

    Options Menu

    Let an Activity to have more options

    Triggered by pressing the Menubutton

    The first six menu items are in icon mode,

    showing in a grid at the bottom of the screen

    Menu is described in XML files stored in

    res/menu/ & inflated into menu with

    MenuInflater

  • 8/4/2019 #MobileDevDay: A crash course in Android Development

    25/29

    Honeycomb UI

    Released for Android Tablets with Large screens

    & Xlarge screens

    With a larger screen estate,Fragments is used to create a multi-pane UI

    Some Options Menu items are promoted into

    the more accessible Action Bar

  • 8/4/2019 #MobileDevDay: A crash course in Android Development

    26/29

    Publishing

    Published in Application Package (APK) format

    that holds the Dalvik executable, resources,

    assets, certificates & Android Manifest

    Published on

    Android Market

    3rd-Party Market such as Amazon Appstore

    Device or Telcos Market

  • 8/4/2019 #MobileDevDay: A crash course in Android Development

    27/29

    Signing

    All APKs must be signed to be deployed

    Developing using debug key

    Publishing using own self-signed key via

    Android Tools > Export Signed Application

    Package in Eclipse

  • 8/4/2019 #MobileDevDay: A crash course in Android Development

    28/29

    Distributing via Web Site

    Distributed viaPublic web site with ads or in-app purchase

    Internal distribution for internal use only

    Configure APK MIME type as

    application/vnd.android.package-archive

    Users download to SD Card via URL/QR Code

    and install via default Package Installer

  • 8/4/2019 #MobileDevDay: A crash course in Android Development

    29/29

    Where to get help?

    http://developer.android.com/ Books about Android with codes samples

    SDK Samples such as API Demos (via Create

    Project from existing example)

    Google IO Android tracks videos

    Android Developer Community meetup such as

    CodeAndroid Malaysia