Android for Java Developers OSCON 2010. Marko Gargenta Marakana

Similar documents
Android For Java Developers. Marko Gargenta Marakana

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

Android Basics. Xin Yang

Hello World! Some code

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

Mobile Application Development

ECWM511 MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction to Android

Android Introduction. Hello Mihail L. Sichitiu 1

Google s Android: An Overview

Introduction to Android. CSG250 Wireless Networks Fall, 2008

Android Development. Marc Mc Loughlin

Android Application Development. Daniel Switkin Senior Software Engineer, Google Inc.

Building an Android client. Rohit Nayak Talentica Software

Chapter 2 Getting Started

Android 多 核 心 嵌 入 式 多 媒 體 系 統 設 計 與 實 作

ECWM511 MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction to Android

Università Degli Studi di Parma. Distributed Systems Group. Android Development. Lecture 2 Android Platform. Marco Picone

An Introduction to Android

Lecture 1 Introduction to Android

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

4. The Android System

Programming with Android: System Architecture. Dipartimento di Scienze dell Informazione Università di Bologna

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

MMI 2: Mobile Human- Computer Interaction Android

Android. Learning Android Marko Gargenta. Tuesday, March 11, 14

Hacking your Droid ADITYA GUPTA

TUTORIALS AND QUIZ ANDROID APPLICATION SANDEEP REDDY PAKKER. B. Tech in Aurora's Engineering College, 2013 A REPORT

Android app development course

Introduction to Android

Mobile Application Development 2014

Developing Android Apps: Part 1

Deep Inside Android. OpenExpo Zurich September 25 th, Gilles Printemps - Senior Architect. Copyright 2007 Esmertec AG.

Basics. Bruce Crawford Global Solutions Manager

Specialized Android APP Development Program with Java (SAADPJ) Duration 2 months

Android Architecture. Alexandra Harrison & Jake Saxton

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

Here to take you beyond Mobile Application development using Android Course details

App Development for Android. Prabhaker Matet

Android Geek Night. Application framework

Overview of CS 282 & Android

A Short Introduction to Android

Jordan Jozwiak November 13, 2011

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

ANDROID INTRODUCTION TO ANDROID

Graduate presentation for CSCI By Janakiram Vantipalli ( Janakiram.vantipalli@colorado.edu )

Programming the Android Platform. Logistics

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

Mobility Introduction Android. Duration 16 Working days Start Date 1 st Oct 2013

Praktikum Entwicklung Mediensysteme (für Master)

ANDROID PROGRAMMING - INTRODUCTION. Roberto Beraldi

Android Application Development

ITG Software Engineering

Android (Basic + Advance) Application Development

Android Developer Fundamental 1

An Introduction to Android. Huang Xuguang Database Lab. Inha University

Android Application Development

Now that we have the Android SDK, Eclipse and Phones all ready to go we can jump into actual Android development.

UNIVERSITY AUTHORISED EDUCATION PARTNER (WDP)

BEGIN ANDROID JOURNEY IN HOURS

Introduction to Android SDK Jordi Linares

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

Developer's Cookbook. Building Applications with. The Android. the Android SDK. A Addison-Wesley. James Steele Nelson To

Getting started with Android and App Engine

Software Environments of Smartphone Applications

Creating and Using Databases for Android Applications

Frameworks & Android. Programmeertechnieken, Tim Cocx

AndroLIFT: A Tool for Android Application Life Cycles

ANDROID BASED MOBILE APPLICATION DEVELOPMENT and its SECURITY

Intro to Android Development 2. Accessibility Capstone Nov 23, 2010

A software stack for mobile devices:

ANDROID. Programming basics

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

SDK Quick Start Guide

ANDROID PROGRAMMING - INTRODUCTION. Roberto Beraldi

Mobile Applications Grzegorz Budzyń Lecture. 2: Android Applications

Android Concepts and Programming TUTORIAL 1

Learning Android Marko Gargenta

Introduction to NaviGenie SDK Client API for Android

Introduction to Android Development. Jeff Avery CS349, Mar 2013

Running a Program on an AVD

Android. Lecture 1. Learning Android Marko Gargenta. Friday, March 22, 13

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

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

Mocean Android SDK Developer Guide

Workshop on Android and Applications Development

06 Team Project: Android Development Crash Course; Project Introduction

How To Develop Android On Your Computer Or Tablet Or Phone

Gauthier Picard. Ecole Nationale Supérieure des Mines

CS 696 Mobile Phone Application Development Fall Semester, 2009 Doc 9 Location & Maps Sept 29, 2009

Android Programming and Security

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

Introduction to Android Development. Daniel Rodrigues, Buuna 2014

Tutorial #1. Android Application Development Advanced Hello World App

1. Introduction to Android

Android Development Tutorial. Human-Computer Interaction II (COMP 4020) Winter 2013

ANDROID OPERATING SYSTEM

Smartphone market share

COURSE CONTENT. GETTING STARTED Select Android Version Create RUN Configuration Create Your First Android Activity List of basic sample programs

Wireless Systems Lab. First Lesson. Wireless Systems Lab

The Android Platform

Transcription:

Android for Java Developers OSCON 2010 Marko Gargenta Marakana

About Marko Gargenta Developed Android Bootcamp for Marakana. Trained over 1,000 developers on Android. Clients include Qualcomm, Sony-Ericsson, Motorola, Texas Instruments, Cisco, Sharp, DoD. Author of upcoming Learning Android by O Reilly. Spoke at OSCON, ACM, IEEE, SDC. Organizes SFAndroid.org

Agenda The Stack Android SDK Hello World! Main Building Blocks Android User Interface OperaIng System Features Debugging Summary

ANDROID STACK

The Stack

Linux Kernel Android runs on Linux. Linux provides as well as: Hardware abstraction layer Memory management Process management Networking Applications Home Contacts Phone Browser Other Activity Manager Package Manager Telephony Manager Application Framework Window Manager Resource Manager Content Providers Location Manager View System Notiication Manager Users never see Linux sub system Surface Manager Media Framework Libraries SQLite Android Runtime The adb shell command opens Linux shell OpenGL SGL FreeType SSL WebKit libc Core Libs Delvik VM Display Driver Camera Driver Linux Kernel Flash Driver Binder Driver Keypad Driver WiFi Driver Audio Driver Power Mgmt

NaIve Libraries Bionic, a super fast and small license-friendly libc library optimized for embedded use Applications Home Contacts Phone Browser Other Surface Manager for composing window manager with off-screen buffering Activity Manager Package Manager Telephony Manager Application Framework Window Manager Resource Manager Content Providers Location Manager View System Notiication Manager 2D and 3D graphics hardware support or software simulation Surface Manager OpenGL Media Framework FreeType Libraries SQLite WebKit Android Runtime Core Libs Media codecs offer support for major audio/video codecs SGL SSL libc Delvik VM SQLite database Display Driver Keypad Driver Camera Driver WiFi Driver Linux Kernel Flash Driver Audio Driver Binder Driver Power Mgmt WebKit library for fast HTML rendering

Dalvik Dalvik VM is Google s implementation of Java VM Optimized for mobile devices Key Dalvik differences: - Register-based versus stack-based VM - Dalvik runs.dex files - More efficient and compact implementation - Different set of Java libraries than SDK

ApplicaIon Framework The rich set of system services wrapped in an intuitive Java API. Applications Home Contacts Phone Browser Other This ecosystem that developers can easily tap into is what makes writing apps for Android easy. Location, web, telephony, WiFi, Bluetooth, notifications, media, camera, just to name a few. Activity Manager Package Manager Surface Manager OpenGL Telephony Manager Application Framework Window Manager Media Framework FreeType Resource Manager Libraries SQLite WebKit Content Providers Location Manager View System Notiication Manager Android Runtime Core Libs SGL SSL libc Delvik VM Display Driver Camera Driver Linux Kernel Flash Driver Binder Driver Keypad Driver WiFi Driver Audio Driver Power Mgmt

Dalvik Executable + Resources = APK Must be signed (but debug key is okay for development) Many markets with different policies ApplicaIons

Android Java = Java SE AWT/Swing + Android API Android and Java

Android SDK - What s in the box SDK Tools Docs Platforms Data Skins Images Samples Add-ons Google

HELLO WORLD!

Create New Project Use the Eclipse tool to create a new Android project. Here are some key constructs: Project Target App name Package AcIvity Eclipse construct minimum to run whatever Java package Java class

The Manifest File <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.marakana" android:versioncode="1" android:versionname="1.0"> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".helloandroid" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> </application> <uses-sdk android:minsdkversion="5" /> </manifest>

The Layout Resource <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> </LinearLayout>

The Java File package com.marakana; import android.app.activity; import android.os.bundle; public class HelloAndroid extends Activity { /** Called when the activity is first created. */ @Override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); } }

Running on Emulator

MAIN BUILDING BLOCKS

AcIviIes Activity is to an application what a web page is to a website. Sort of. Android Application Main Activity Another Activity Another Activity

AcIvity Lifecycle Starting Activities have a welldefined lifecycle. The Android OS manages your activity by changing its state. You fill in the blanks. Stopped (1) oncreate() (2) onstart() (3) onrestoreinstancestate() (4) onresume() Running (3) onresume() (2) onstart() (1) onrestart() onresume() (1) onsaveinstancestate() (2) onstop() (1) onsaveinstancestate() (2) onpause() Paused ondestroy() or <process killed> <process killed> Destroyed

Intents Intents represent an events or actions. Android Application Main Activity Intent Another Activity They are to Android apps what hyperlinks are to websites. Sort of. Android Application Main Activity Intent Intent Another Activity Intents can be implicit or explicit.

Services Services are code that runs in the background. They can be started and stopped. Services doesn t have UI.

Service Lifecycle Service also has a lifecycle, but it s much simpler than activity s. onstart() Starting (1) oncreate() (2) onstart() An activity typically starts and stops a service to do some work for it in the background, such as play music, check for new tweets, etc. Stopped ondestroy() or <process killed> Destroyed onstop() Running

Content Providers Content Providers share content with applications across application boundaries. Examples of built-in Content Providers are: Contacts, MediaStore, Settings and more. Content URI insert() update() delete() query() Content Provider

Broadcast Receivers An Intent-based publish-subscribe mechanism. Great for listening system events such as SMS messages.

MyTwiVer A Real World App Update list MyTwitter Activity Preference Activity Timeline Receiver Timeline Activity Updates Status via web service Read Prefs Twitter.com Read/write preferences Prefs XML Pull timeline updates via web service Read Prefs Notify of new status Updater Service Start at boot Insert updates in DB Update ListView Timeline Adapter Pull timeline from DB Timeline DB Boot Receiver

ANDROID USER INTERFACE

Two UI Approaches Procedural You write Java code Similar to Swing or AWT Declara?ve You write XML code Similar to HTML of a web page You can mix and match both styles. Declarative is preferred: easier and more tools

XML- Based User Interface Use WYSIWYG tools to build powerful XML-based UI. Easily customize it from Java. Separate concerns.

Dips and Sps px (pixel) in (inches) mm (millimeters) pt (points) dp (density- independent pixel) dip sp Dots on the screen Size as measured by a ruler Size as measured by a ruler 1/72 of an inch Abstract unit. On screen with 160dpi, 1dp=1px synonym for dp and ocen used by Google Similar to dp but also scaled by users font size preference

Views and Layouts ViewGroup ViewGroup View View View View Layouts contain other Views, or other Layouts.

Common UI Components Android UI includes many common modern UI widgets, such as Buttons, Tabs, Progress Bars, Date and Time Pickers, etc.

SelecIon Components Some UI widgets may be linked to zillion pieces of data. Examples are ListView and Spinners (pull-downs).

Adapters Adapter Data Source To make sure they run smoothly, Android uses Adapters to connect them to their data sources. A typical data source is an Array or a Database.

Complex Components Certain high-level components are simply available just like Views. Adding a Map or a Video to your application is almost like adding a Button or a piece of text.

Menus and Dialogs

Graphics & AnimaIon Android has rich support for 2D graphics. You can draw & animate from XML. You can use OpenGL for 3D graphics.

MulImedia AudioPlayer lets you simply specify the audio resource and play it. VideoView is a View that you can drop anywhere in your activity, point to a video file and play it. XML: <VideoView android:id="@+id/video" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_gravity="center /> Java: player = (VideoView) findviewbyid(r.id.video); player.setvideopath("/sdcard/samplevideo.3gp"); player.start();

OPERATING SYSTEM FEATURES

Security Each Android application runs inside its own Linux process. Android Application Linux Process Additionally, each application has its own sandbox file system with its own set of preferences and its own database. DB Prefs File System Other applications cannot access any of its data, unless it is explicitly shared.

File System The file system has three main mount points. One for system, one for the apps, and one for whatever. Each app has its own sandbox easily accessible to it. No one else can access its data. The sandbox is in /data/data/com.marakana/ SDCard is expected to always be there. It s a good place for large files, such as movies and music. Everyone can access it.

Cloud to Device Push Big deal for many pull-based apps. Will make devices use less battery.

Preferences Your app can support complex preferences quite easily. You define your preferences in an XML file and the corresponding UI and data storage is done for free.

SQLite Database Android ships with SQLite3 SQLite is Zero configuration Serverless Single database file Cross-Platform Compact Public Domain Database engine. May you do good and not evil May you find forgiveness for yourself and forgive others May you share freely, never taking more than you give.

DEBUGGING ANDROID APPS

LogCat The universal, most versatile way to track what is going on in your app. Can be viewed via command line or Eclipse. Logs can be generated both from SDK Java code, or low-level C code via Bionic libc extension.

Debugger Your standard debugger is included in SDK, with all the usual bells & whistles.

TraceView TraceView helps you profile you application and find bottlenecks. It shows execution of various calls through the entire stack. You can zoom into specific calls.

Hierarchy Viewer Hierarchy Viewer helps you analyze your User Interface. Base UI tends to be the most expensive part of your application, this tool is very useful.

Summary Android is open and complete system for mobile development. It is based on Java and augmented with XML. Android is being adopted very quickly both by users, carriers, and manufacturers. It takes about 3-5 days of intensive training to learn Android application development for someone who has basic Java (or similar) experience. Marko Gargenta, Marakana.com marko@marakana.com +1-415-647-7000 Licensed under Creative Commons License (cc-by-nc-nd) non-commercial. Please Share!