App Development for Smart Devices. Lec #2: Android Tools, Building Applications, and Activities



Similar documents
Android Environment SDK

Android Environment SDK

Getting Started with Android Development

Università Degli Studi di Parma. Distributed Systems Group. Android Development. Lecture 1 Android SDK & Development Environment. Marco Picone

Android Development Tutorial. Nikhil Yadav CSE40816/ Pervasive Health Fall 2011

Introduction to Android: Hello, Android! 26 Mar 2010 CMPT166 Dr. Sean Ho Trinity Western University

Android Application Development - Exam Sample

Advantages. manage port forwarding, set breakpoints, and view thread and process information directly

Hello World. by Elliot Khazon

ANDROID APPS DEVELOPMENT FOR MOBILE AND TABLET DEVICE (LEVEL I)

The "Eclipse Classic" version is recommended. Otherwise, a Java or RCP version of Eclipse is recommended.

l What is Android? l Getting Started l The Emulator l Hello World l ADB l Text to Speech l Other APIs (camera, bitmap, etc)

How To Develop An Android App On An Android Device

Introduction to Android Programming (CS5248 Fall 2015)

App Development for Smart Devices

Android Development. 吳 俊 興 國 立 高 雄 大 學 資 訊 工 程 學 系

Introduction to Android. CSG250 Wireless Networks Fall, 2008

Developing In Eclipse, with ADT

Android Development. Marc Mc Loughlin

Android Programming: Installation, Setup, and Getting Started

Installing the Android SDK

Android Development Setup [Revision Date: 02/16/11]

ADT Plugin for Eclipse

Islamic University of Gaza. Faculty of Engineering. Computer Engineering Department. Mobile Computing ECOM Eng. Wafaa Audah.

directory to "d:\myproject\android". Hereafter, I shall denote the android installed directory as

Running a Program on an AVD

INTRODUCTION TO ANDROID CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 11 02/15/2011

Android Tutorial. Larry Walters OOSE Fall 2011

Fahim Uddin 1. Java SDK

Jordan Jozwiak November 13, 2011

Android Programming. Høgskolen i Telemark Telemark University College. Cuong Nguyen,

How to build your first Android Application in Windows

Reminders. Lab opens from today. Many students want to use the extra I/O pins on

Mobile Security - Tutorial 1. Beginning Advanced Android Development Brian Ricks Fall 2014

Android Setup Phase 2

Android Development. Lecture AD 0 Android SDK & Development Environment. Università degli Studi di Parma. Mobile Application Development

Developing NFC Applications on the Android Platform. The Definitive Resource

Programming with Android: SDK install and initial setup. Dipartimento di Informatica: Scienza e Ingegneria Università di Bologna

How To Run A Hello World On Android (Jdk) On A Microsoft Ds.Io (Windows) Or Android Or Android On A Pc Or Android 4 (

Android 4.4 App Development Essentials

Android For Java Developers. Marko Gargenta Marakana

CS378 -Mobile Computing. Android Overview and Android Development Environment

Oracle FLEXCUBE Direct Banking Android Tab Client Installation Guide Release

Mobile Application Development

Android: How To. Thanks. Aman Nijhawan

Lab 0 (Setting up your Development Environment) Week 1

Android Application Development

5 reasons to choose Streamezzo SDK over Android SDK Page 2

Frameworks & Android. Programmeertechnieken, Tim Cocx

CS 528 Mobile and Ubiquitous Computing Lecture 2: Android Introduction and Setup. Emmanuel Agu

How to Create an Android Application using Eclipse on Windows 7

With a single download, the ADT Bundle includes everything you need to begin developing apps:

Introduction to Android Development

AndroLIFT: A Tool for Android Application Life Cycles

IOIO for Android Beginners Guide Introduction

Android Programming and Security

System Reference 2013

Tutorial on Basic Android Setup

Introduction to Android Development. Jeff Avery CS349, Mar 2013

Android Basics. Xin Yang

Published: SWD

Chapter 2 Getting Started

OpenCV on Android Platforms

An Introduction to Android Application Development. Serdar Akın, Haluk Tüfekçi

Android 4.4 App Development Essentials

ECWM511 MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction to Android

1) SETUP ANDROID STUDIO

Developing Android Apps: Part 1

06 Team Project: Android Development Crash Course; Project Introduction

Application Development Setup Guide

Developing for MSI Android Devices

Mocean Android SDK Developer Guide

1. Introduction to Android

Mobile Applications Grzegorz Budzyń Lecture. 2: Android Applications

How to develop your own app

Android Development Exercises Version Hands On Exercises for. Android Development. v

How to Install Applications (APK Files) on Your Android Phone

Tutorial: Android Object API Application Development. SAP Mobile Platform 2.3

Homeschool Programming, Inc.

Programming with Android: SDK install and initial setup. Dipartimento di Informatica: Scienza e Ingegneria Università di Bologna

Introduction to Android

Android Development Tools for Eclipse

How To Develop Android On Your Computer Or Tablet Or Phone

Building an Android client. Rohit Nayak Talentica Software

Android Environment Emulator

Q1. What method you should override to use Android menu system?

Технологии Java. Android: Введение. Кузнецов Андрей Николаевич. Санкт-Петербургский Государственный Политехнический Университет

Login with Amazon Getting Started Guide for Android. Version 2.0

Programming with Android

Hacking your Droid ADITYA GUPTA

Download and Installation Instructions. Android SDK and Android Development Tools (ADT)

Android Application Development: Hands- On. Dr. Jogesh K. Muppala

Download and Installation Instructions. Android SDK and Android Development Tools (ADT) Microsoft Windows

Getting Started with Android Programming (5 days) with Android 4.3 Jelly Bean

Table of Contents. Adding Build Targets to the SDK 8 The Android Developer Tools (ADT) Plug-in for Eclipse 9

Android: Setup Hello, World: Android Edition. due by noon ET on Wed 2/22. Ingredients.

WA1826 Designing Cloud Computing Solutions. Classroom Setup Guide. Web Age Solutions Inc. Copyright Web Age Solutions Inc. 1

Home Course Catalog Schedule Pricing & Savings Training Options Resources About Us

Android Fundamentals 1

Transcription:

App Development for Smart Devices CS 495/595 - Fall 2011 Lec #2: Android Tools, Building Applications, and Activities Tamer Nadeem Dept. of Computer Science

Objective Understand Android Tools Setup Android Development Environment Create HelloWorld Application Understand HelloWorld Structure Familiarize with Android Application Types and Components Understand the Role of Android Activity Know how to Build and Run Android Application Introduce Debug and Publish Page 2 Fall 2011 CS 495/595 - App Development for Smart Devices

Developing for Android Eclipse Android SDK Android Development Tools (ADT) Android Virtual Devices (AVD) & SDK Manager The Android Emulator Dalvik Debug Monitor Services (DDMS) The Android Debug Bridge (ADB) Page 3 Fall 2011 CS 495/595 - App Development for Smart Devices

Eclipse Page 4 Fall 2011 CS 495/595 - App Development for Smart Devices

Eclipse Eclipse IDE for Java Developers Open http://www.eclipse.org/ Select "Downloads" Select Eclipse IDE for Java Developers, 122MB Select Windows32 Extract zip file to c:\eclipse Installation Tutorial: http://archive.eclipse.org/technology/phoenix/europa/eclipseideforj avadevelopers/ Test First Development Tutorial: http://archive.eclipse.org/technology/phoenix/europa/testfirstwithe clipse/ Page 5 Fall 2011 CS 495/595 - App Development for Smart Devices

Android SDK Check Your Development Computer Supported Operating Systems Windows XP (32-bit), Vista (32- or 64-bit), or Windows 7 (32- or 64-bit) Mac OS X 10.5.8 or later (x86 only) Linux (tested on Ubuntu Linux, Lucid Lynx) Supported Development Environments JDK SE 6.0 32bit version (including JRE) Eclipse IDE for Java Developers - Indigo version 32bit version Android Development Tools (ADT) plugin SDK Installation Android SDK starter package installer_r12-windows.zip Android SDK Components Run Android SDK setup From Available packages window, select all items and then click install Page 6 Fall 2011 CS 495/595 - App Development for Smart Devices

ADT plugin Start Eclipse, then select Help > Install New Software Click Add, in the top-right corner. In the Add Repository dialog that appears, enter "ADT Plugin" for the Name and the following URL for the Location: https://dlssl.google.com/android/eclipse/ Click OK Wait and you should see "Developer Tools" in the Available Software dialog, select the checkbox next to Developer Tools and click Next. In the next window, you'll see a list of the tools to be downloaded. Click Next. Click Finish. Page 7 Fall 2011 CS 495/595 - App Development for Smart Devices

Configure ADT plugin Modify your ADT preferences in Eclipse to point to the Android SDK directory: 1) Select Window > Preferences... to open the Preferences panel (Mac OS X: Eclipse > Preferences). 2) Select Android from the left panel. 3) You may see a dialog asking whether you want to send usage statistics to Google. If so, make your choice and click Proceed. You cannot continue with this procedure until you click Proceed. 4) For the SDK Location, locate your downloaded SDK directory. Click Apply, then OK. (Spaces in path causes an error, if you are using Windows64. For example, C:\Program Files(x86)\Android\android-sdk C:\PROGRA~2\Android\android-sdk) Page 8 Fall 2011 CS 495/595 - App Development for Smart Devices

Android Emulator Device Page 9 Fall 2011 CS 495/595 - App Development for Smart Devices

Android Emulator Hardware Option Characteristic Description Device ram size The amount of physical RAM on the device, in megabytes. Default value is "96". Touch-screen support Whether there is a touch screen or not on the device. Default value is "yes". Trackball support Whether there is a trackball on the device. Default value is "yes". Keyboard support Whether the device has a QWERTY keyboard. Default value is "yes". DPad support Whether the device has DPad keys. Default value is "yes". GSM modem support Whether there is a GSM modem in the device. Default value is "yes". Camera support Whether the device has a camera. Default value is "no". Maximum horizontal camera Default value is "640". pixels Maximum vertical camera pixels Default value is "480". GPS support Whether there is a GPS in the device. Default value is "yes". Battery support Whether the device can run on a battery. Default value is "yes". Accelerometer Whether there is an accelerometer in the device. Default value is "yes". Audio recording support Whether the device can record audio. Default value is "yes". Audio playback support Whether the device can play audio. Default value is "yes". SD Card support Whether the device supports insertion/removal of virtual SD Cards. Default value is "yes". Cache partition support Whether we use a /cache partition on the device. Default value is "yes". Cache partition size Default value is "66MB". Abstracted LCD density Sets the generalized density characteristic used by the AVD's screen. Default value is "160". Trackball support Whether there is a trackball present. Page 10 Fall 2011 CS 495/595 - App Development for Smart Devices

Android Emulator Controls Page 11 Fall 2011 CS 495/595 - App Development for Smart Devices

Your First Android Project Select File -> New -> Project -> Android -> Android Project and create the Android project right-click the project and select Run As > Android Application Page 12 Fall 2011 CS 495/595 - App Development for Smart Devices

Project Structure src/ - Java packages. Each package can have multiple.java files representing different classes. res/layout/ - XML files that specify the layout of each screen. res/values/ - XML files used as references by other files. res/drawable-hdpi/, res/drawable-mdpi/, and res/drawable-ldpi/ - high, medium, and low dots-perinch resolution pictures. res/color, res/menu, res/anim assets/ - additional non-media files. AndroidManifest.xml specifies the project to the Android OS. Auto-generated files (do not modify): gen/ contains auto-generated code. Class R.java generated by Android Asset Packaging Tool (aapt). default.properties contains project settings. Page 13 Fall 2011 CS 495/595 - App Development for Smart Devices

Project Structure Page 14 Fall 2011 CS 495/595 - App Development for Smart Devices

Resources, Package, Manifest Page 15 Fall 2011 CS 495/595 - App Development for Smart Devices

Android Software Stack Page 16 Fall 2011 CS 495/595 - App Development for Smart Devices

Application Framework Page 17 Fall 2011 CS 495/595 - App Development for Smart Devices

Android Component Model Packaging: APK File (Android Package) > Collection of components > Components share a set of resources Preferences, Database, File space > Components share a Linux process By default, one process per APK > APKs are isolated Communication via Intents or AIDL > Every component has a managed lifecycle Task (what users know as applications) > Collection of related activities > Capable of spanning multiple processes > Associated with its own UI history stack > Processes are started & stopped as needed > Processes may be killed to reclaim resources Page 18 Fall 2011 CS 495/595 - App Development for Smart Devices

Android Application Components i) Activity: Activity is a visual screen for interaction of user with the application. Depends upon design, an application may consists of one or more activities ii) Views: The User interface of an Activities is build with widgets. ii) Service: Service do not have a visual interface, it runs in the back ground, like play back music and fetching data from the network. iii) Broadcast Receiver: Broadcast receiver receive broadcast announcements and response to them according to the situation. iv) Content Provider: Content provider is a SQLite database, which supports the sharing and accessing of data among applications. v) Intents: Asynchronous messages which allow the application to request functionality from other services or activities. vi) Others parts are Android widgets/live Folders and Live Wallpapers. Page 19 Fall 2011 CS 495/595 - App Development for Smart Devices

Example of Components Interactions Page 20 Fall 2011 CS 495/595 - App Development for Smart Devices

Types of Android Applications Foreground Activity: An application that s only useful when it s in the foreground and is effectively suspended when it s not visible. Background Service: An application with limited interaction that, apart from when being configured, spends most of its lifetime hidden. Examples of this include call screening applications or SMS autoresponders. Intermittent Activity: Expects some interactivity but does most of its work in the background. Often these applications will be set up and then run silently, notifying users when appropriate. A common example would be a media player. Widgets: Interactive visual components that users can add to their home screens. Usually used to display information such as battery levels, weather forecasts, or the date and time. Page 21 Fall 2011 CS 495/595 - App Development for Smart Devices

Android s Activity An activity is an application component that provides a screen with which users can interact Activity is usually a single screen Implemented as a single class extending Activity Displays user interface controls (views) Reacts on user input / events An application typically consists of several activities Each screen is typically implemented by one activity Each activity can then start another activity (new screen) An activity may return a result to the previous activity "main" activity is presented to the user when launching the application for the first time. Each activity receives callbacks due to a change in its state during its lifecycle whether the system is creating it, stopping it, resuming it, or destroying it. Page 22 Fall 2011 CS 495/595 - App Development for Smart Devices

Activity Lifecycle Foreground Lifetime Visible Lifetime Entire Lifetime Page 23 Fall 2011 CS 495/595 - App Development for Smart Devices

Activity Lifecycle Page 24 Fall 2011 CS 495/595 - App Development for Smart Devices

Utilizing Activity Lifecycle Functions Simple exercise to see the activity lifecycle in action each overridden function is explicit and a Toast command is added to show on screen when the function is entered Run it on an Android device and try various cases: Changing the screen orientation destroys and recreates the activity from scratch. Pressing the Home button pauses the activity, but does not destroy it. Pressing the Application icon might start a new instance of the activity, even if the old one was not destroyed. Letting the screen sleep pauses the activity and the screen awakening resumes it. (This is similar to taking an incoming phone call.) Page 25 Fall 2011 CS 495/595 - App Development for Smart Devices

Back Stack Tasks and Activities Multiple Activity Instances Multiple Tasks Page 26 Fall 2011 CS 495/595 - App Development for Smart Devices

Notes on Activity Starting Activity: void startactivity (Intent intent) void startactivityforresult (Intent intent, int requestcode) void onactivityresult (int requestcode, int resultcode, Intent data) Shutting Down Activity: void finish () void finishactivity (int requestcode) Saving Activity Status void onsaveinstancestate (Bundle outstate) void onrestoreinstancestate (Bundle savedinstancestate) Activity A starts Activity B: A's onpause() B's oncreate(), onstart(), and onresume() (Activity B now has user focus.) A s onstop(), if A is no longer visible Page 27 Fall 2011 CS 495/595 - App Development for Smart Devices

Building Android Project Eclipse outputs an.apk file automatically to the bin folder of the project Contains all information to run the application, such as compiled.dex files, a binary version of AndroidManifest.xml, compiled resources (resources.arsc) and uncompiled resource files. Eclipse automatically builds application, enables debugging and signs the.apk with a debug key, by default. Page 28 Fall 2011 CS 495/595 - App Development for Smart Devices

Building Android Project (detailed) Page 29 Fall 2011 CS 495/595 - App Development for Smart Devices

Running Running on the emulator To run (or debug) your application, select Run > Run (or Run > Debug) from the Eclipse menu bar. Be certain to create multiple AVDs upon which to test your application. Running on a device Ensure application is debuggable by setting android:debuggable="true" of the<application> element in AndroidManifest.xml. Set up the device to allow installation of non-market applications. On the device, go to Settings > Applications and enable Unknown sources. Enable USB Debugging on the device. On the device, Settings > Applications > Development > USB debugging. For Windows, use Device Manager to install a USB driver for adb. (<androidsdk>\extras\google\usb_driver) Page 30 Fall 2011 CS 495/595 - App Development for Smart Devices

Manual Application Installation Manual Installation using adb App Package: <workspace>\<project Name>\bin\<Project Name>.apk Need adb tool located at <sdk>/platform-tools/ Modify Device settings as in Running on a Device In Command Prompt, type: adb [-d -e] install <path>/<file>.apk Manual Uninstall On device, go to Applications Menu ->Settings->Manage Applications. Select the application which you want to Uninistall, and click on the Uninstall button. Page 31 Fall 2011 CS 495/595 - App Development for Smart Devices

Debugging The main components that comprise Android debugging environment are: Device or Android Virtual Device Delvik Debug Monitoring Service (DDMS): graphical program that can capture screenshots, gather thread and stack information, spoof incoming calls and SMS messages, and other features. The Android Debug Bridge (ADB): provides various device management capabilities. JDWP debugger: allows you to step through code, view variable values, and pause execution of an application. A JDWP-compliant debugger is already included in Eclipse. Page 32 Fall 2011 CS 495/595 - App Development for Smart Devices

DDMS (Window > Open Perspective > Other... > DDMS) http://developer.android.com/guide/developing/debugging/ddms.html Page 33 Fall 2011 CS 495/595 - App Development for Smart Devices

Debug (Window > Open Perspective > Debug) Page 34 Fall 2011 CS 495/595 - App Development for Smart Devices

Putting Application on Market Signing Your Application with Eclipse To distribute your application, however, you must build your application in release mode and sign the.apk file with your own private key. right-click the project in the Package Explorer and select Android Tools > Export Unsigned Application Package. Then specify the file location for the unsigned.apk. Versioning Your Applications android:versioncode, android:versionname android:minsdkversion, android:targetsdkversion, android:maxsdkversion Preparing to Publish Check the following checklist: http://developer.android.com/guide/publishing/preparing.html Publishing on Android Market Android Market developer registration: http://market.android.com/publish Page 35 Fall 2011 CS 495/595 - App Development for Smart Devices

Questions? Page 36 Spring 2011 CS 752/852 - Wireless and Mobile Networking

Recommended Assignment Have your development environment setup Programming: Hello World Programming: Utilizing lifecycle activities Page 37 Fall 2011 CS 495/595 - App Development for Smart Devices