Android Step by Step

download Android Step by Step

of 22

Transcript of Android Step by Step

  • 8/3/2019 Android Step by Step

    1/22

    1

    BuildingBuildingHelloWorldHelloWorld

    Android ApplicationAndroid Application

    Step by Step.Step by Step.

    Sang ShinSang ShinMichle GarocheMichle Garoche

    www.javapassion.comwww.javapassion.comLearn with Passion!Learn with Passion!

  • 8/3/2019 Android Step by Step

    2/22

    2

    Disclaimer

    Portions of this presentation are modificationsbased on work created and shared by theAndroid Open Source Project

    > http://code.google.com/policies.html

    They are used according to terms described inthe Creative Commons 2.5 Attribution License

    > http://creativecommons.org/licenses/by/2.5/

  • 8/3/2019 Android Step by Step

    3/22

    3

    Goals of This Presentation

    Get you started with Android applicationdevelopment

    Get you know the development environment

    >

    Will focus on Eclipse-based Android developmentenvironment (instead of command-line-basedone)

    Get you be exposed to the basic building blocksof an Android application in a cursory manner

    > The details will be covered in the rest of thecourse

  • 8/3/2019 Android Step by Step

    4/22

    4

    Topics

    Installation and configuration

    Building blocks of Android application

    > Activities

    >

    Layout resource files> AndroidManifest.xml

    > Resource files - strings.xml

    > R.java

  • 8/3/2019 Android Step by Step

    5/22

    5

    Installation &Installation &

    ConfigurationConfiguration

  • 8/3/2019 Android Step by Step

    6/22

    6

    Software Needed

    JDK (Java Development Kit)

    > Android application is Java application

    Eclipse IDE>

    Editor, Debugger, profiler, deployment Android SDK

    > Libraries, samples, documentation, handsetemulators, debugger, command line tools

    Eclipse ADT (Android Development Tools) plug-in

    > Give you a powerful, integrated develpmentenvironment

  • 8/3/2019 Android Step by Step

    7/227

    Creating Android Project using Eclipse

    Automatic creationbuilding blocks of anAndroid application

    > Starting Activity

    class> Layout resource file

    > AndroidManifest.xml

    > strings.xml

    > R.java> Android library

  • 8/3/2019 Android Step by Step

    8/228

    Building Blocks ofBuilding Blocks of

    Android ApplicationAndroid Application

  • 8/3/2019 Android Step by Step

    9/229

    Building Blocks of Android Application

    Activity classes

    Layout resource files

    Resource files>

    strings.xml AndroidManifest.xml

    R.java (automatically created from resourcefiles)

    Android library (automatically configured)

  • 8/3/2019 Android Step by Step

    10/2210

    Building Blocks of Android Application

  • 8/3/2019 Android Step by Step

    11/2211

    Activity Class

    Each Activity class typically represents a screen

    > Like a JSP page in a Web application

    The onCreate() method of Activity class getscalled by the Android system when yourActivity starts> You create your UI inside the onCreate() method

    Every Activity has to be described in theAndroidManifest.xml file

    An Activity is typically chosen as a starting oneof your application - like a class that has amain() method in Java

    > Special configuration in AndroidManifest.xml

  • 8/3/2019 Android Step by Step

    12/2212

    Activity Class Example

    package com.javapassion;

    import android.app.Activity;import android.os.Bundle;

    publicclass HelloWorldActivity extends Activity {

    /** Called when the activity is first created. */ @Override publicvoid onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);

    //Create UI using Layout resource filesetContentView(R.layout.main);

    }}

  • 8/3/2019 Android Step by Step

    13/22

    13

    Layout Resource Files

    Every screen has a corresponding layoutresource file> Unless you create UI programmatically

    Each activity class specifies which layoutresource file to use for each screen itrepresents

    > Using setContentView(R.layout.main);

    Are located under /res/layoutdirectory

  • 8/3/2019 Android Step by Step

    14/22

    14

    Layout Resource File Example

  • 8/3/2019 Android Step by Step

    15/22

    15

    Resource Files - strings.xml

    Let you define the text strings of yourapplications in a well-known file> Rather than in Java code

    > Rather than in Layout resource files

    The strings are then referred to through thenames assigned to them

    > The mapping is done through R.java

    Located under /res/values directory

  • 8/3/2019 Android Step by Step

    16/22

  • 8/3/2019 Android Step by Step

    17/22

    17

    AndroidManifest.xml file

    Every application must have a manifest filecalled AndroidManifest.xml file (with preciselythat name) in its root directory.

    The manifest presents essential information

    about the application to the Android system,information the system must have before it canrun any of the application's code.

  • 8/3/2019 Android Step by Step

    18/22

    18

    Info. in AndroidManifest.xml file

    Java package for the application.> The package name serves as a unique identifier for

    the application.

    Activities

    > One activity is designated as a starting Activity

  • 8/3/2019 Android Step by Step

    19/22

    19

    AndroidManifest.xml

  • 8/3/2019 Android Step by Step

    20/22

    20

    R.java

    Automatically created by Android system for allresources defined

  • 8/3/2019 Android Step by Step

    21/22

    21

    R.java

  • 8/3/2019 Android Step by Step

    22/22

    22

    Thank you!Thank you!

    Sang ShinSang ShinMichle GarocheMichle Garoche

    www.javapassion.comwww.javapassion.comLearn with Passion!Learn with Passion!