SlideShare uma empresa Scribd logo
1 de 30
Android Worshop

 Marc Mc Loughlin
   14/12/2010
Getting Started
• Android Developer Website
  http://developer.android.com/
   –   Dev Guide
   –   Reference
   –   Resources
   –   Video / Blog

• Setting up the SDK
  http://developer.android.com/sdk/installing.html
   – Install Eclipse IDE
   – Download SDK
   – Set system PATH to point to C:<path to sdk>tools
        • Allow shell wide access to SDK tools
             – Android
             – Emulator
             – adb, etc
   – Install the Android Development Tools (ADT) Plugin
   – Windows: Install USB driver to connect to external device
Development Tools
• Android Developer Tools (ADT) plugin
   – Lets you access development tools from Eclipse
   – Provides Android Project wizard, exports your
      project to APK
   – Allows you to create an Android Virtual Device
      (AVD)
   http://developer.android.com/guide/developing/
   eclipse-adt.html

• Android Virtual Device
   – Device configuration that lets you model
     device specifications
       • Hardware (memory)
       • Android OS version
       • Storage
   – Created using either the ADT or the android
     tool (SDK-directory/tools/)
   – Runs on the Emulator
Development Tools
• Emulator
   – Included in SDK (SDK-DIRECTORY/tools/)
   – Load AVD configuration to specify Android version,
     hardware for the emulator instance
   – Uses disk images on development machine to simulate
     flash images on device
   – Has networking capabilities but requires setup

• Android Debug Bridge (adb)
   – Allows access to the emulator instance or Android Device
       • Allows Eclipse access to device data
             – Installing applications
             – Debugging
       • Allows developers to execute commands (adb devices)
             – Installing applications (adb -s emulator_name install
               helloWorld.apk)
             – Copying files to and from device (adb pull / adb push)
             – Provides shell to run commands on device (adb -s
               emulator_name shell)
Android Architecture
•   Applications
      • Core applications shipped with
          device (email client, calendar,
          maps, browser, etc)
      • All user installed applications
•   Application Framework
      • Set of services and systems that
          your application can use
      • Activity Manager, Content
          providers, Resource Manager
•   Core Libraries
      • Subset of J2SE
•   Android Runtime
      • Dalvik virtual machine optimized
          for mobile devices
      • Runs class files (dex files)
•   Libraries
      • C/C++ libraries but called
          through java interfaces
•   Linux kernel
      • Underlying operating system
Android Application Components
•   Activities                                 •   Broadcast Receivers
     — Activity: A window to                        – Listens for events
       draw user interface                          – Receives broadcast
       components on                                  announcements (Intents)
     — Numerous activities =                          and reacts to them
       Task = Android App                             (timezone changes, etc)
     — Each window is a subclass
       of the activity class




• Services                                     • Content providers
    — Background                                  — Persist data
       processes                                  — SQLite database
    — Carries out any long         ― Intents      — Shared preferences
       process
Intents

•Activities, Services and Broadcast
Receivers talk to each other via
Intents

•Intents = messages among the
application components
     •Can be within your application:
     calling an activity or service in
     your application
     •Or System wide: accessing the
     address book activity
     •Accessing functionality of other
     applications (e.g. zxing)

•An intent contains
     •Action (what has to be done)
     •Data (Info)
Manifest file




• Each application runs on an individual Dalvik virtual machine inside a linux
  process

• To access other applications and specific parts of the API it must have
  permission
    – An applications permissions are set in it’s manifest file
    – Manifest file: Tells the android operating system about the application
        • Permissions
        • Its components (Activities, Services, Content Providers, etc)
        • Has to be updated when you add specific elements to your application (activities, sdcard
          access, location manager access, etc.)
Building your User Interface (UI)
Activities
Android - Activities
• Activity class
   – Each UI Window extends the
     activity class (android.app.Activity)
       • activity is a frame or window to hold
         the GUI

   – Each activity loads a view

   – Handles user inputs
       • You put your code to handle user
         interaction in the activity

   – Activity has three states
       • Active or Running: Activity is the
         focus of users actions
       • Paused: Activity has lost focus but
         still visible
       • Stopped: Activity is completely
         hidden from user
/src

Android Project   /gen
                         This is where all the java sources files are put. Similar to /src
                         folder in normal Java projects. Source files should be organised
                         into packages

                         Another source folder but contains only a single but very
                         important java source file called R.java. That is automatically
                         created in eclipse via the ADT
                         R.java keeps track of all the resources in your project so you can
                         reference them in your code
                  /android
                         Contains the android libraries that are need for the project
                         similar to “/lib” folder in normal java projects
                  /res
                         Contains external resources (interface layouts, application data,
                         images etc.) that are used by the android application
                         /res/drawable-ldpi
                         /res/drawable-mdpi
                         /res/drawable-hdpi
                                 Contains all images needed for the application
                         /res/layout
                                 Contains all the UI layouts for the application
                         /res/values
                                 Contains xml files that hold key – value pairs that can be
                                 references in the application
                                          Color codes
                                          Strings
                                          dimensions
                  /assets
                         You can any external resources here
                         Resources are in raw format and can only be read
                         programmatically
                  AndroidManifest.xml
                         Contains all the information about the application, every
                         application must have one
                         Info about activities, services, permissions
Activities
• Activity Manager
   – Manages the lifecycle of
     activities
   – As it moves between states
     specific methods are called
       • Hooks you can override to do
         work when the state changes
   – Manages back stack for user
     navigation
Android Activities
                       Lifecycle Methods
• All activities should implement the onCreate(Bundle) method
    – Called every time an activity is launched
    – This is where activity is initialised
        • Loading views
        • Initiating fields

• Nearly all activities will implement:
    – onResume()
        • Creating database connections
        • Getting intent information
    – onPause() method
        • This is where persist (save) any data
    – onDestroy()
        • This is where clean up is generally carried out
        • Killing any other threads attached to the application, etc.
Creating your view
                                        LinearLayout linearLayout = new LinearLayout(this);
• User Interfaces can be                parentView.addView(linearLayout, relativeParams);

  created in two ways:                  TextView tv1 = new TextView(this);
   1. Create layouts at                 tv1.setId(1);
                                        TextView tv2 = new TextView(this);
      programmatically at runtime       tv2.setId(2);
   2. Declare UI elements in xml
      and loaded as a resource          layout.addView(tv1);
                                        layout.addView(tv2, lp);
      (Preferred) at runtime
      • Create UI in xml and then
        reference them in your code     <RelativeLayout...>
      • At runtime android parses the    <TextView>
        xml resource files and             android:id="@+id/label1" />
        instantiates them               </TextView>
                                         <TextView ...
                                           android:id="@+id/label2"
• Allows you to separate the               android:layout_below: "@id/label1" />
  presentation from code                </RelativeLayout>
Creating the view layout in xml
•   Similar to creating webpages in html
     – Tree of xml elements
                                                  <?xml version="1.0" encoding="utf-8"?>
     – Each element of the tree is a view         <LinearLayout
         class(TextView, ImageView, etc.)         xmlns:android="http://schemas.android.com/apk/res/and
                                                  roid"
                                                    android:orientation="vertical"
•   Must contain one root element (View or          android:layout_width="fill_parent"
    ViewGroup) where additional views are           android:layout_height="fill_parent"
    added as children                               >
     – View: A widget that appears on screen      <TextView
        (buttons, text boxes, labels, etc.)         android:id="@+id/textview"
                                                    android:layout_width="fill_parent"
     – ViewGroup: Provides layout structure for     android:layout_height="wrap_content"
        your views                                  android:text="@string/hello"
          • LinearLayout                            />
                                                  </LinearLayout>
          • AbsoluteLayout
          • TableLayout
          • RelativeLayout
          • FrameLayout
          • Scrollview
Creating the view layout in xml
•   Once a root element is defined you build
    your view by adding more view elements to
    it

•   Each View or ViewGroup has it’s own xml
    attributes
     – Some are common to all
            • “id” attribute: Gives the View a
               unique ID to idenfiy it. Used to
               add new resources to R.java
            • Layout Parameters:
               “layout_height” / “layout_width”
     – Some View have their own specific
          attributes
            • TextView: textsize
External Resources
                                                                   Table 1: Resource Directories
                                                       Directory                  Resource Type
•   Stored in “/res” directory in the project
                                                                                  XML files that define tween
                                                       anim/
                                                                                  animations.
•   Types of resources                                                            XML files that define a state list of
     –   Color information                             color/
                                                                                  colors.
     –   Layout (UI) information
     –   Strings (Application text)                                                Bitmap files (.png, .9.png, .jpg,
     –   Etc..                                         drawable/                   .gif) or XML files that are
                                                                                   compiled into drawable resources
•   R.java file managed by ADT creates new                                         XML files that define a user
    resource ID when resource added to                 layout/
                                                                                   interface layout.
    application
     –   This resource ID can be reference in source                               XML files that define application
         code                                          menu/                       menus, such as an Options Menu,
                                                                                   Context Menu, or Sub Menu.
•   When packaged each Android application
    has a resource table where it keeps all the
    resource information                                                           Arbitrary files to save in their raw
                                                       raw/
                                                                                   form.
•   In an Android project the sub directories of
    the /res directory must follow specific
    patterns (see Table 1)                                                         XML files that contain simple
                                                       values/                     values, such as strings, integers,
                                                                                   and colors.

                                                                                   Arbitrary XML files that can be
                                                       xml/
                                                                                   read at runtime
Loading your view into an activity
                                                             Referencing View elements in
   Loading View                                              source
   •    UI layout resource loaded in onCreate()              To apply logic in your source code for views
        using setContentView() method                        created in an xml layout you must reference them
        inherited from the activity class                    in your source
          –   You pass the reference to the UI layout you    1.    Create a variable of your view type in your
              create to the setContentView (int                    source code
              layoutResID)                                   2.    Then assign it to a view in your layout file
          –   R.layout.main                                        using findViewByID(int id) method
                                                                   inherited from the activity class
                                                                    –   You pass in the id of the view you want to
   •    Your activity provides the window and                           reference
        you fill the window using                                   –   The findViewByID(int id) returns a object of
        setContentView (int layoutResID)                                type View so you must cast the view to the
          –   If you do not call this method no UI will be              specific instance you created
              displayed

@Override                                                    @Override
protected void onCreate(Bundle savedInstanceState) {         protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);                   super.onCreate(savedInstanceState);
       this.setContentView(R.layout.main);                   this.setContentView(R.layout.main);
}
                                                             TextView textView1 =
                                                             (TextView)this.findViewById(R.id.button1);
                                                             }
Android application package file:
Manifest File                            .apk file
• A xml file saved as                    • Just a zip file similar to
  AndroidManifest.xml
• Every application must have one,         other java archive files jar,
  it specifies:                            war, etc.
    – All components of an application
    – What activity is displayed on      • It contains:
      application launch
                                            – all the application code in
    – The android API the application
      requires                                .dex files (class files)
    – The permissions the application       – Resources
      has (sdcard read/write,
      networking, etc.)                     – Resource table
• Each activity added to the                – Assets and manifest
  application must be declared in
  the manifest file
User Interaction
UI events
• Events are fired every time a user interacts with a View
• Capture these events to react to these interactions
• How?
    – The View class provides interfaces (or event listeners) with callback methods
        • These methods are call by Android when an action occurs on a view to which a listener is
          registered to
    – The following are some of the listener interfaces that can be implemented
        •   OnClickListener
        •   OnFocusChangeListener
        •   OnKeyListener
        •   OnLongClickListener
        •   OnTouchListener

• Procedure
    – Create your listener interface
        • Numerous ways to do this, the best way is to let your activity implement the listener
          interface
    – Set the view’s onClickListener to your listener
        Button button1 = (Button)this.findViewById(R.id.button1);
        button1.setOnClickListener(this);
Implementing OnClickListener
OnClickListener implemented in                                   Anonymous Implementation of
your activity (best way)                                         OnClickListener
public class StartActivity extends Activity implements           public class StartActivity extends Activity{
OnClickListener{
                                                                       @Override
     @Override                                                         protected void onCreate(Bundle savedInstanceState) {
     protected void onCreate(Bundle savedInstanceState) {              super.onCreate(savedInstanceState);
     super.onCreate(savedInstanceState);                               this.setContentView(R.layout.startactivitylayout);
     this.setContentView(R.layout.startactivitylayout);
                                                                       TextView textView1 =
     TextView textView1 =                                              (TextView)this.findViewById(R.id.textview);
     (TextView)this.findViewById(R.id.textview);
                                                                       Button button1 = (Button)this.findViewById(R.id.button1);
     Button button1 = (Button)this.findViewById(R.id.button1);
     button1.setOnClickListener(this);                                 button1.setOnClickListener(new OnClickListener(){
     }
                                                                               @Override
     @Override                                                                 public void onClick(View v) {
     public void onClick(View v) {                                             // Code to deal with user interaction
     // Code to deal with user interaction
                                                                                   }
                                                                             });
     }
                                                                       }
                                                                 }
}
Moving between Activities
• An Intent is a message that holds data
  about action that has to be carried out

• Intents can be used to activate appplication
                                                                  Intents
  components: activities, services and
  broadcast receivers
    – They are delivered by passing them through
      specific methods
        • activities: startActivity(), startActivityForResult()
        • services: startService(), bindService()
        • Broadcast receivers: sendBroadcast(),
          sendOrderedBroadcast()


• Can access components of native and
  installed applications as well!

• An intent can hold the following pieces of
  information
    – Action: what action has to be performed
    – Data: data that can operated on
    – Category: provides more data about the action
    – Type: type of intent data
    – Component: Specifics the specific name of
      component calls to use
    – Extras: Any additional information to be sent
Explicit Intents
• Have a specified component that provides the
  exact class to be run
• Usually do not include any more information
  except data you want to pass to the component
  Intent intent = new Intent();
  intent.setClassName("ie.marc", "ie.marc.SecondActivity");
  this.startActivity(intent);

  Intent intent = new Intent(this, SecondActivity.class);
  this.startActivity(intent);

  Intent intent = new Intent("com.google.zxing.client.android.SCAN");
  intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
  startActivityForResult(intent, 0)
Implicit Intents
•   Intents don’t explicitly name a target component

•   Android tests the data in the Intent Object against intent filters associated with potential targets

•   Intent Resolution: maps intent to Activity, BroadcastReceiver or service

•   To ascertain what component best serves the intent following information is analysed
     –   Action
     –   Category
     –   Data
•   This data is matched to intent filters set in other applications

    Intent intent = new Intent();                              <intent-filter>
    intent.setAction("android.intent.action.VIEW");              <action android:name="android.intent.action.VIEW" />
                                                                 <category
    intent.setData(Uri.parse("http://www.lit.ie"));
                                                               android:name="android.intent.category.DEFAULT" />
    this.startActivity(intent);                                  <scheme android:name="http" />
                                                                 <scheme android:name="https" />
                                                                 <scheme android:name="file" />
                                                               </intent-filter>
Launching Activities
• Launching an activity with no data
  returned
    – Use startActivity(Intent)
         Intent intent = new Intent(this,
         SecondActivity.class);
         this.startActivity(intent);

• Launching an activity where data
  needs to be returned
    – Use startActivityForResult(intent,
      resultcode)

    – The launched activity returns the data
      by creating an intent and passing it to
      setResult(int resultCode, intent)

    – The calling activity must Override
      onActivityResult(int requestCode, int
      resultCode, Intent data)
         • This is called by the activity manager
         • It passes in the data in an intent and
           result code from the returning activity
Launching an activity where data
                 needs to be returned example
     Activity 1 – Calling activity                                          Activity 2 – Launched activity
@Override
public void onClick(View arg0) {
       Intent intent = new Intent(this, SecondActivity.class);
       this.startActivityForResult(intent, REQUESTCODE);

}
                                                                            Intent data = new Intent();
@Override
                                                                            data.putExtra(SecondActivity.RETURNEDNAME,
protected void onActivityResult(int requestCode, int resultCode, Intent
data) {
                                                                            textInput.getText().toString());
        switch(requestCode){                                                this.setResult(Activity.RESULT_OK, data);
        case REQUESTCODE:                                                   this.finish();
               if (resultCode == RESULT_OK){
                  textView1.setText(data.getStringExtra("returnedText"));
               }else{
                  textView1.setText(data.getStringExtra("A problem
                  occured when getting the returned information"));
               }
               break;
               default:
               break;
               }
}
Getting Started
• Refresh your knowledge of Java (Do some tutorials)
• - Java tutorial on classes, inheritance & interfaces
   http://download.oracle.com/javase/tutorial/java/concepts/index.html
   - Tutorial on interfaces,
   http://download.oracle.com/javase/tutorial/java/IandI/index.html

• Learn how to use the Debugger!
    – http://eclipsetutorial.sourceforge.net/debugger.html

• Look at the tutorials on the Android Developer site
    – http://developer.android.com/resources/tutorials/hello-world.html
    – http://developer.android.com/resources/tutorials/views/index.html
    – http://developer.android.com/resources/tutorials/notepad/index.htm
      l

Mais conteĂşdo relacionado

Mais procurados

Android tutorial
Android tutorialAndroid tutorial
Android tutorialkatayoon_bz
 
Android tutorial
Android tutorialAndroid tutorial
Android tutorialEd Zel
 
Android application-component
Android application-componentAndroid application-component
Android application-componentLy Haza
 
Android apps development
Android apps developmentAndroid apps development
Android apps developmentRaman Pandey
 
Part 2 android application development 101
Part 2 android application development 101Part 2 android application development 101
Part 2 android application development 101Michael Angelo Rivera
 
Android dev o_auth
Android dev o_authAndroid dev o_auth
Android dev o_authlzongren
 
View groups containers
View groups containersView groups containers
View groups containersMani Selvaraj
 
Introduction to android sessions new
Introduction to android   sessions newIntroduction to android   sessions new
Introduction to android sessions newJoe Jacob
 
Android components
Android componentsAndroid components
Android componentsNAVEENA ESWARAN
 
Android App development and test environment, Understaing android app structure
Android App development and test environment, Understaing android app structureAndroid App development and test environment, Understaing android app structure
Android App development and test environment, Understaing android app structureVijay Rastogi
 
How to create android applications
How to create android applicationsHow to create android applications
How to create android applicationsTOPS Technologies
 
Case Study: Cool Clock - An Intro to Android Development
Case Study: Cool Clock - An Intro to Android DevelopmentCase Study: Cool Clock - An Intro to Android Development
Case Study: Cool Clock - An Intro to Android DevelopmentRichard Creamer
 
Android programming
Android programmingAndroid programming
Android programmingvijay_uttam
 
Beginning android
Beginning android Beginning android
Beginning android Igor R
 

Mais procurados (20)

Android tutorial
Android tutorialAndroid tutorial
Android tutorial
 
Android tutorial
Android tutorialAndroid tutorial
Android tutorial
 
Android tutorial
Android tutorialAndroid tutorial
Android tutorial
 
Android application-component
Android application-componentAndroid application-component
Android application-component
 
Android apps development
Android apps developmentAndroid apps development
Android apps development
 
Android tutorial
Android tutorialAndroid tutorial
Android tutorial
 
Android
AndroidAndroid
Android
 
Part 2 android application development 101
Part 2 android application development 101Part 2 android application development 101
Part 2 android application development 101
 
Training android
Training androidTraining android
Training android
 
Android dev o_auth
Android dev o_authAndroid dev o_auth
Android dev o_auth
 
View groups containers
View groups containersView groups containers
View groups containers
 
Introduction to android sessions new
Introduction to android   sessions newIntroduction to android   sessions new
Introduction to android sessions new
 
Android components
Android componentsAndroid components
Android components
 
Android App development and test environment, Understaing android app structure
Android App development and test environment, Understaing android app structureAndroid App development and test environment, Understaing android app structure
Android App development and test environment, Understaing android app structure
 
Ios - Introduction to platform & SDK
Ios - Introduction to platform & SDKIos - Introduction to platform & SDK
Ios - Introduction to platform & SDK
 
How to create android applications
How to create android applicationsHow to create android applications
How to create android applications
 
Case Study: Cool Clock - An Intro to Android Development
Case Study: Cool Clock - An Intro to Android DevelopmentCase Study: Cool Clock - An Intro to Android Development
Case Study: Cool Clock - An Intro to Android Development
 
Android programming
Android programmingAndroid programming
Android programming
 
Beginning android
Beginning android Beginning android
Beginning android
 
Android beginners David
Android beginners DavidAndroid beginners David
Android beginners David
 

Semelhante a Android Development

Introduction to Android Development Part 1
Introduction to Android Development Part 1Introduction to Android Development Part 1
Introduction to Android Development Part 1Kainda Kiniel Daka
 
Android Workshop_1
Android Workshop_1Android Workshop_1
Android Workshop_1Purvik Rana
 
Android project architecture
Android project architectureAndroid project architecture
Android project architectureSourabh Sahu
 
Android For Java Developers
Android For Java DevelopersAndroid For Java Developers
Android For Java DevelopersMike Wolfson
 
Lec005 android start_program
Lec005 android start_programLec005 android start_program
Lec005 android start_programEyad Almasri
 
Introduction to Android (before 2015)
Introduction to Android (before 2015)Introduction to Android (before 2015)
Introduction to Android (before 2015)Chien-Ming Chou
 
Introduction to Android Development and Security
Introduction to Android Development and SecurityIntroduction to Android Development and Security
Introduction to Android Development and SecurityKelwin Yang
 
Android session-1-sajib
Android session-1-sajibAndroid session-1-sajib
Android session-1-sajibHussain Behestee
 
Intro To Android App Development
Intro To Android App DevelopmentIntro To Android App Development
Intro To Android App DevelopmentMike Kvintus
 
Android Introduction
Android IntroductionAndroid Introduction
Android Introductionaswapnal
 
Android Technology
Android TechnologyAndroid Technology
Android TechnologyAnshul Sharma
 
Android For Java Developers
Android For Java DevelopersAndroid For Java Developers
Android For Java DevelopersMike Wolfson
 
Android Jumpstart Jfokus
Android Jumpstart JfokusAndroid Jumpstart Jfokus
Android Jumpstart JfokusLars Vogel
 
Introduction to Android and Android Studio
Introduction to Android and Android StudioIntroduction to Android and Android Studio
Introduction to Android and Android StudioSuyash Srijan
 
Introduction to android basics
Introduction to android basicsIntroduction to android basics
Introduction to android basicsHasam Panezai
 
Android fundamentals and tutorial for beginners
Android fundamentals and tutorial for beginnersAndroid fundamentals and tutorial for beginners
Android fundamentals and tutorial for beginnersBoom Shukla
 
Java talks. Android intoduction for develompment
Java talks. Android intoduction for develompmentJava talks. Android intoduction for develompment
Java talks. Android intoduction for develompmentAlexei Miliutin
 

Semelhante a Android Development (20)

Introduction to Android Development Part 1
Introduction to Android Development Part 1Introduction to Android Development Part 1
Introduction to Android Development Part 1
 
Android Workshop_1
Android Workshop_1Android Workshop_1
Android Workshop_1
 
Android project architecture
Android project architectureAndroid project architecture
Android project architecture
 
Android For Java Developers
Android For Java DevelopersAndroid For Java Developers
Android For Java Developers
 
Lec005 android start_program
Lec005 android start_programLec005 android start_program
Lec005 android start_program
 
Introduction to Android (before 2015)
Introduction to Android (before 2015)Introduction to Android (before 2015)
Introduction to Android (before 2015)
 
Introduction to Android Development and Security
Introduction to Android Development and SecurityIntroduction to Android Development and Security
Introduction to Android Development and Security
 
Android session-1-sajib
Android session-1-sajibAndroid session-1-sajib
Android session-1-sajib
 
Session 2 beccse
Session 2 beccseSession 2 beccse
Session 2 beccse
 
Unit I- ANDROID OVERVIEW.ppt
Unit I- ANDROID OVERVIEW.pptUnit I- ANDROID OVERVIEW.ppt
Unit I- ANDROID OVERVIEW.ppt
 
Intro To Android App Development
Intro To Android App DevelopmentIntro To Android App Development
Intro To Android App Development
 
Android Introduction
Android IntroductionAndroid Introduction
Android Introduction
 
Android Technology
Android TechnologyAndroid Technology
Android Technology
 
Android For Java Developers
Android For Java DevelopersAndroid For Java Developers
Android For Java Developers
 
Android Jumpstart Jfokus
Android Jumpstart JfokusAndroid Jumpstart Jfokus
Android Jumpstart Jfokus
 
Introduction to Android and Android Studio
Introduction to Android and Android StudioIntroduction to Android and Android Studio
Introduction to Android and Android Studio
 
Introduction to android basics
Introduction to android basicsIntroduction to android basics
Introduction to android basics
 
Android fundamentals and tutorial for beginners
Android fundamentals and tutorial for beginnersAndroid fundamentals and tutorial for beginners
Android fundamentals and tutorial for beginners
 
PPT Companion to Android
PPT Companion to AndroidPPT Companion to Android
PPT Companion to Android
 
Java talks. Android intoduction for develompment
Java talks. Android intoduction for develompmentJava talks. Android intoduction for develompment
Java talks. Android intoduction for develompment
 

Último

AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...apidays
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusZilliz
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vĂĄzquez
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbuapidays
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 

Último (20)

AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 

Android Development

  • 1. Android Worshop Marc Mc Loughlin 14/12/2010
  • 2. Getting Started • Android Developer Website http://developer.android.com/ – Dev Guide – Reference – Resources – Video / Blog • Setting up the SDK http://developer.android.com/sdk/installing.html – Install Eclipse IDE – Download SDK – Set system PATH to point to C:<path to sdk>tools • Allow shell wide access to SDK tools – Android – Emulator – adb, etc – Install the Android Development Tools (ADT) Plugin – Windows: Install USB driver to connect to external device
  • 3. Development Tools • Android Developer Tools (ADT) plugin – Lets you access development tools from Eclipse – Provides Android Project wizard, exports your project to APK – Allows you to create an Android Virtual Device (AVD) http://developer.android.com/guide/developing/ eclipse-adt.html • Android Virtual Device – Device configuration that lets you model device specifications • Hardware (memory) • Android OS version • Storage – Created using either the ADT or the android tool (SDK-directory/tools/) – Runs on the Emulator
  • 4. Development Tools • Emulator – Included in SDK (SDK-DIRECTORY/tools/) – Load AVD configuration to specify Android version, hardware for the emulator instance – Uses disk images on development machine to simulate flash images on device – Has networking capabilities but requires setup • Android Debug Bridge (adb) – Allows access to the emulator instance or Android Device • Allows Eclipse access to device data – Installing applications – Debugging • Allows developers to execute commands (adb devices) – Installing applications (adb -s emulator_name install helloWorld.apk) – Copying files to and from device (adb pull / adb push) – Provides shell to run commands on device (adb -s emulator_name shell)
  • 5. Android Architecture • Applications • Core applications shipped with device (email client, calendar, maps, browser, etc) • All user installed applications • Application Framework • Set of services and systems that your application can use • Activity Manager, Content providers, Resource Manager • Core Libraries • Subset of J2SE • Android Runtime • Dalvik virtual machine optimized for mobile devices • Runs class files (dex files) • Libraries • C/C++ libraries but called through java interfaces • Linux kernel • Underlying operating system
  • 6. Android Application Components • Activities • Broadcast Receivers — Activity: A window to – Listens for events draw user interface – Receives broadcast components on announcements (Intents) — Numerous activities = and reacts to them Task = Android App (timezone changes, etc) — Each window is a subclass of the activity class • Services • Content providers — Background — Persist data processes — SQLite database — Carries out any long ― Intents — Shared preferences process
  • 7. Intents •Activities, Services and Broadcast Receivers talk to each other via Intents •Intents = messages among the application components •Can be within your application: calling an activity or service in your application •Or System wide: accessing the address book activity •Accessing functionality of other applications (e.g. zxing) •An intent contains •Action (what has to be done) •Data (Info)
  • 8. Manifest file • Each application runs on an individual Dalvik virtual machine inside a linux process • To access other applications and specific parts of the API it must have permission – An applications permissions are set in it’s manifest file – Manifest file: Tells the android operating system about the application • Permissions • Its components (Activities, Services, Content Providers, etc) • Has to be updated when you add specific elements to your application (activities, sdcard access, location manager access, etc.)
  • 9. Building your User Interface (UI)
  • 11. Android - Activities • Activity class – Each UI Window extends the activity class (android.app.Activity) • activity is a frame or window to hold the GUI – Each activity loads a view – Handles user inputs • You put your code to handle user interaction in the activity – Activity has three states • Active or Running: Activity is the focus of users actions • Paused: Activity has lost focus but still visible • Stopped: Activity is completely hidden from user
  • 12. /src Android Project /gen This is where all the java sources files are put. Similar to /src folder in normal Java projects. Source files should be organised into packages Another source folder but contains only a single but very important java source file called R.java. That is automatically created in eclipse via the ADT R.java keeps track of all the resources in your project so you can reference them in your code /android Contains the android libraries that are need for the project similar to “/lib” folder in normal java projects /res Contains external resources (interface layouts, application data, images etc.) that are used by the android application /res/drawable-ldpi /res/drawable-mdpi /res/drawable-hdpi Contains all images needed for the application /res/layout Contains all the UI layouts for the application /res/values Contains xml files that hold key – value pairs that can be references in the application Color codes Strings dimensions /assets You can any external resources here Resources are in raw format and can only be read programmatically AndroidManifest.xml Contains all the information about the application, every application must have one Info about activities, services, permissions
  • 13. Activities • Activity Manager – Manages the lifecycle of activities – As it moves between states specific methods are called • Hooks you can override to do work when the state changes – Manages back stack for user navigation
  • 14. Android Activities Lifecycle Methods • All activities should implement the onCreate(Bundle) method – Called every time an activity is launched – This is where activity is initialised • Loading views • Initiating fields • Nearly all activities will implement: – onResume() • Creating database connections • Getting intent information – onPause() method • This is where persist (save) any data – onDestroy() • This is where clean up is generally carried out • Killing any other threads attached to the application, etc.
  • 15. Creating your view LinearLayout linearLayout = new LinearLayout(this); • User Interfaces can be parentView.addView(linearLayout, relativeParams); created in two ways: TextView tv1 = new TextView(this); 1. Create layouts at tv1.setId(1); TextView tv2 = new TextView(this); programmatically at runtime tv2.setId(2); 2. Declare UI elements in xml and loaded as a resource layout.addView(tv1); layout.addView(tv2, lp); (Preferred) at runtime • Create UI in xml and then reference them in your code <RelativeLayout...> • At runtime android parses the <TextView> xml resource files and android:id="@+id/label1" /> instantiates them </TextView> <TextView ... android:id="@+id/label2" • Allows you to separate the android:layout_below: "@id/label1" /> presentation from code </RelativeLayout>
  • 16. Creating the view layout in xml • Similar to creating webpages in html – Tree of xml elements <?xml version="1.0" encoding="utf-8"?> – Each element of the tree is a view <LinearLayout class(TextView, ImageView, etc.) xmlns:android="http://schemas.android.com/apk/res/and roid" android:orientation="vertical" • Must contain one root element (View or android:layout_width="fill_parent" ViewGroup) where additional views are android:layout_height="fill_parent" added as children > – View: A widget that appears on screen <TextView (buttons, text boxes, labels, etc.) android:id="@+id/textview" android:layout_width="fill_parent" – ViewGroup: Provides layout structure for android:layout_height="wrap_content" your views android:text="@string/hello" • LinearLayout /> </LinearLayout> • AbsoluteLayout • TableLayout • RelativeLayout • FrameLayout • Scrollview
  • 17. Creating the view layout in xml • Once a root element is defined you build your view by adding more view elements to it • Each View or ViewGroup has it’s own xml attributes – Some are common to all • “id” attribute: Gives the View a unique ID to idenfiy it. Used to add new resources to R.java • Layout Parameters: “layout_height” / “layout_width” – Some View have their own specific attributes • TextView: textsize
  • 18. External Resources Table 1: Resource Directories Directory Resource Type • Stored in “/res” directory in the project XML files that define tween anim/ animations. • Types of resources XML files that define a state list of – Color information color/ colors. – Layout (UI) information – Strings (Application text) Bitmap files (.png, .9.png, .jpg, – Etc.. drawable/ .gif) or XML files that are compiled into drawable resources • R.java file managed by ADT creates new XML files that define a user resource ID when resource added to layout/ interface layout. application – This resource ID can be reference in source XML files that define application code menu/ menus, such as an Options Menu, Context Menu, or Sub Menu. • When packaged each Android application has a resource table where it keeps all the resource information Arbitrary files to save in their raw raw/ form. • In an Android project the sub directories of the /res directory must follow specific patterns (see Table 1) XML files that contain simple values/ values, such as strings, integers, and colors. Arbitrary XML files that can be xml/ read at runtime
  • 19. Loading your view into an activity Referencing View elements in Loading View source • UI layout resource loaded in onCreate() To apply logic in your source code for views using setContentView() method created in an xml layout you must reference them inherited from the activity class in your source – You pass the reference to the UI layout you 1. Create a variable of your view type in your create to the setContentView (int source code layoutResID) 2. Then assign it to a view in your layout file – R.layout.main using findViewByID(int id) method inherited from the activity class – You pass in the id of the view you want to • Your activity provides the window and reference you fill the window using – The findViewByID(int id) returns a object of setContentView (int layoutResID) type View so you must cast the view to the – If you do not call this method no UI will be specific instance you created displayed @Override @Override protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); super.onCreate(savedInstanceState); this.setContentView(R.layout.main); this.setContentView(R.layout.main); } TextView textView1 = (TextView)this.findViewById(R.id.button1); }
  • 20. Android application package file: Manifest File .apk file • A xml file saved as • Just a zip file similar to AndroidManifest.xml • Every application must have one, other java archive files jar, it specifies: war, etc. – All components of an application – What activity is displayed on • It contains: application launch – all the application code in – The android API the application requires .dex files (class files) – The permissions the application – Resources has (sdcard read/write, networking, etc.) – Resource table • Each activity added to the – Assets and manifest application must be declared in the manifest file
  • 22. UI events • Events are fired every time a user interacts with a View • Capture these events to react to these interactions • How? – The View class provides interfaces (or event listeners) with callback methods • These methods are call by Android when an action occurs on a view to which a listener is registered to – The following are some of the listener interfaces that can be implemented • OnClickListener • OnFocusChangeListener • OnKeyListener • OnLongClickListener • OnTouchListener • Procedure – Create your listener interface • Numerous ways to do this, the best way is to let your activity implement the listener interface – Set the view’s onClickListener to your listener Button button1 = (Button)this.findViewById(R.id.button1); button1.setOnClickListener(this);
  • 23. Implementing OnClickListener OnClickListener implemented in Anonymous Implementation of your activity (best way) OnClickListener public class StartActivity extends Activity implements public class StartActivity extends Activity{ OnClickListener{ @Override @Override protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); super.onCreate(savedInstanceState); this.setContentView(R.layout.startactivitylayout); this.setContentView(R.layout.startactivitylayout); TextView textView1 = TextView textView1 = (TextView)this.findViewById(R.id.textview); (TextView)this.findViewById(R.id.textview); Button button1 = (Button)this.findViewById(R.id.button1); Button button1 = (Button)this.findViewById(R.id.button1); button1.setOnClickListener(this); button1.setOnClickListener(new OnClickListener(){ } @Override @Override public void onClick(View v) { public void onClick(View v) { // Code to deal with user interaction // Code to deal with user interaction } }); } } } }
  • 25. • An Intent is a message that holds data about action that has to be carried out • Intents can be used to activate appplication Intents components: activities, services and broadcast receivers – They are delivered by passing them through specific methods • activities: startActivity(), startActivityForResult() • services: startService(), bindService() • Broadcast receivers: sendBroadcast(), sendOrderedBroadcast() • Can access components of native and installed applications as well! • An intent can hold the following pieces of information – Action: what action has to be performed – Data: data that can operated on – Category: provides more data about the action – Type: type of intent data – Component: Specifics the specific name of component calls to use – Extras: Any additional information to be sent
  • 26. Explicit Intents • Have a specified component that provides the exact class to be run • Usually do not include any more information except data you want to pass to the component Intent intent = new Intent(); intent.setClassName("ie.marc", "ie.marc.SecondActivity"); this.startActivity(intent); Intent intent = new Intent(this, SecondActivity.class); this.startActivity(intent); Intent intent = new Intent("com.google.zxing.client.android.SCAN"); intent.putExtra("SCAN_MODE", "QR_CODE_MODE"); startActivityForResult(intent, 0)
  • 27. Implicit Intents • Intents don’t explicitly name a target component • Android tests the data in the Intent Object against intent filters associated with potential targets • Intent Resolution: maps intent to Activity, BroadcastReceiver or service • To ascertain what component best serves the intent following information is analysed – Action – Category – Data • This data is matched to intent filters set in other applications Intent intent = new Intent(); <intent-filter> intent.setAction("android.intent.action.VIEW"); <action android:name="android.intent.action.VIEW" /> <category intent.setData(Uri.parse("http://www.lit.ie")); android:name="android.intent.category.DEFAULT" /> this.startActivity(intent); <scheme android:name="http" /> <scheme android:name="https" /> <scheme android:name="file" /> </intent-filter>
  • 28. Launching Activities • Launching an activity with no data returned – Use startActivity(Intent) Intent intent = new Intent(this, SecondActivity.class); this.startActivity(intent); • Launching an activity where data needs to be returned – Use startActivityForResult(intent, resultcode) – The launched activity returns the data by creating an intent and passing it to setResult(int resultCode, intent) – The calling activity must Override onActivityResult(int requestCode, int resultCode, Intent data) • This is called by the activity manager • It passes in the data in an intent and result code from the returning activity
  • 29. Launching an activity where data needs to be returned example Activity 1 – Calling activity Activity 2 – Launched activity @Override public void onClick(View arg0) { Intent intent = new Intent(this, SecondActivity.class); this.startActivityForResult(intent, REQUESTCODE); } Intent data = new Intent(); @Override data.putExtra(SecondActivity.RETURNEDNAME, protected void onActivityResult(int requestCode, int resultCode, Intent data) { textInput.getText().toString()); switch(requestCode){ this.setResult(Activity.RESULT_OK, data); case REQUESTCODE: this.finish(); if (resultCode == RESULT_OK){ textView1.setText(data.getStringExtra("returnedText")); }else{ textView1.setText(data.getStringExtra("A problem occured when getting the returned information")); } break; default: break; } }
  • 30. Getting Started • Refresh your knowledge of Java (Do some tutorials) • - Java tutorial on classes, inheritance & interfaces http://download.oracle.com/javase/tutorial/java/concepts/index.html - Tutorial on interfaces, http://download.oracle.com/javase/tutorial/java/IandI/index.html • Learn how to use the Debugger! – http://eclipsetutorial.sourceforge.net/debugger.html • Look at the tutorials on the Android Developer site – http://developer.android.com/resources/tutorials/hello-world.html – http://developer.android.com/resources/tutorials/views/index.html – http://developer.android.com/resources/tutorials/notepad/index.htm l