133
DONG NAI UNIVERSITY OF TECHNOLOGY 1 5. Using Android OS / Devices 4. Introduction to Android OS 3. Software Installation 2. Mobile / Tablet OSs 1. Subject introduction 6. Eclipse debug with Android app 7. Components of the Android Application 8. Units of measurement 9. XML Primer 10. Application’s Life Cycle

1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

Embed Size (px)

Citation preview

Page 1: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

1

DONG NAI UNIVERSITY OF TECHNOLOGY

5. Using Android OS / Devices

4. Introduction to Android OS

3. Software Installation

2. Mobile / Tablet OSs

1. Subject introduction

6. Eclipse debug with Android app

7. Components of the Android Application

8. Units of measurement

9. XML Primer

10. Application’s Life Cycle

Page 2: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

2

DONG NAI UNIVERSITY OF TECHNOLOGY

1. Subject introduction

1.1 Topics

1.2 Learning Objectives

1.3 Textbooks

1.4 Test / Grade

1.5 Assignments

1.6 Rules

Page 3: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

3

DONG NAI UNIVERSITY OF TECHNOLOGY

1.1 Topics

Background

Software stack

Activities vs applications

Activity life cycles

Activity states

Resources

Notification Manager

Mobile/Tablet development application

Page 4: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

4

DONG NAI UNIVERSITY OF TECHNOLOGY

1.1 Topics

User Interfaces Views

Layouts

Widgets

UI XML specification

Page 5: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

5

DONG NAI UNIVERSITY OF TECHNOLOGY

1.1 Topics

Intents, Receivers, Adapters Explicit Intents

Implicit Intents

Event Broadcasting with Intents

Event Reception with Broadcast Receivers

Adapters and DataBinding

Page 6: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

6

DONG NAI UNIVERSITY OF TECHNOLOGY

1.1 Topics

Files, Content Providers, Databases Saving and Loading Files

SQLite Databases

Access Exposure to Data Sources through Content

Providers

Content Provider Registration

Native Content Providers

Page 7: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

7

DONG NAI UNIVERSITY OF TECHNOLOGY

1.1 Topics

Common Android APIsNetworking APIsLBS APIs

Web APIsMultimedia APIs

Telephony APIs

And Sensors…

Page 8: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

8

DONG NAI UNIVERSITY OF TECHNOLOGY

1.2 Learning Objectives

Have an appreciation of the Android OS

Know how to develop basic UIs

Know how to broadcast and receive events

Know how to manage data storage through files,

databases, and content providers

Know how to implement basic location-based

services

Know how to use audio and video utilities

Page 9: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

9

DONG NAI UNIVERSITY OF TECHNOLOGY

1.2 Learning Objectives

Know how to access the Internet

Know how to process URL data encoded in

HTML/XML

Know how to capture touch screen events and

recognize touch screen gestures

Become exposed to Android online resources and

communities

Know how to use android APIs, Sensors…

Page 10: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

10

DONG NAI UNIVERSITY OF TECHNOLOGY

1.3 Textbooks

[1] Unlocking Android[2] The Busy Coders Guide to Android Development[3]Beginning Android Application Development – WeiMengle – Wrox -2011[4] Android Wireless Development -Lauren Darcey , Shane Conder

[5] Professional Android Application Development –MalestromWeb : http://developer.android.com

Page 11: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

11

DONG NAI UNIVERSITY OF TECHNOLOGY

1.4 Test / Grade

Attendance Mid term lab test Final lab test Homework assignments in every week Final Project Final project will require technical writing (project proposal submission, source documentation, description) Code in java (Eclipse) There will be reading suggestions Final test

Page 12: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

12

DONG NAI UNIVERSITY OF TECHNOLOGY

1.5 Assignments

All assignments will be submitted via Assembla

All assignments using namespace

vn.edu.dntu.it.Studentname.ID. labNo

vn.edu.dntu.it.lethihoa.0891233.Lab32

Grades will be submitted via Assembla

Late submission will not be accepted

Page 13: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

13

DONG NAI UNIVERSITY OF TECHNOLOGY

1.5 Assignments Server - Tools

– MS Source safe – SVN server (open source) – MS Team Foundation server

Host – Server in Lan – Host throught internet

• www.Googlecode (code.google.com) (public) • www.Assembla.com (public) • www.Projectlocker.com (public & private) • http://sourceforge.net

Client – TortoiseSVN – Visual studio…

Page 14: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

14

DONG NAI UNIVERSITY OF TECHNOLOGY

1.5 Assignments

http://tortoisesvn.net/downloads.html

Register account : http://www.assembla.com/ and create space to submit assignments Detail

Page 15: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

15

DONG NAI UNIVERSITY OF TECHNOLOGY

1.6 Rules

- Attendance 75%

- Do homework

- Do lab project

- Research on internet

Page 16: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

16

DONG NAI UNIVERSITY OF TECHNOLOGY

2. Mobile / Tablet OSs

MobileSymbian

Ubuntu

BlackBerry

Windows Phone

Bada

MeeGo

IOS WebOS

Android

Page 17: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

17

DONG NAI UNIVERSITY OF TECHNOLOGY

Bada

Samsung

Closed source

http://developer.bada.com

Page 18: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

18

DONG NAI UNIVERSITY OF TECHNOLOGY

C/C++ J2EM

http://www.developer.nokia.com/

Page 19: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

19

DONG NAI UNIVERSITY OF TECHNOLOGY

Windows Phone

http://dev.windowsphone.com C#VB.netXAML

Page 20: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

20

DONG NAI UNIVERSITY OF TECHNOLOGY

WebOS from HP

open sourced

running on the Linux kernel

Visual Studio

https://developer.palm.com/

C/C++

Java

Page 21: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

21

DONG NAI UNIVERSITY OF TECHNOLOGY

IOS Apple

derived from Mac OS X. Objective C – iPhone SDk

https://developer.apple.com

Page 22: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

22

DONG NAI UNIVERSITY OF TECHNOLOGY

BlackBerry

https://developer.blackberry.com/

Page 23: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

23

DONG NAI UNIVERSITY OF TECHNOLOGY

Android Google Inc

free and open source

Linux-derived OS

Java (Android SDK)

http://developer.android.com/

Page 24: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

24

DONG NAI UNIVERSITY OF TECHNOLOGY

Ubuntu

http://www.ubuntu.com/devices/android

Professional Ubuntu Mobile Development

Page 25: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

25

DONG NAI UNIVERSITY OF TECHNOLOGY

MeeGoopen source

Nokia + Intel

https://meego.com/developers

C++

Page 26: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

26

DONG NAI UNIVERSITY OF TECHNOLOGY

Mobile Characterized Limited resources

Screen CPU RAM (no virtual) No harddisk Battery

Input data: many ways

Compact Not much room Reuse of common component is impotant

Phone functionality always highest priority

Always on

Page 27: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

27

DONG NAI UNIVERSITY OF TECHNOLOGY

3. Software Installation

3.1 Introdution to software tools

3.2 Install Android SDK

Page 28: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

28

DONG NAI UNIVERSITY OF TECHNOLOGY

3.1 Introdution to software tools Android Environment: Eclipse & ADT

The Android Development Tools (ADT) adds extensions to the Eclipse IDE. It allows: create and debug Android applications easier and faster. Advantages:

It gives you access to other Android development tools from inside the Eclipse IDE: take screenshots, Debug / set breakpoints, and view thread and process information directly from Eclipse.

It provides a New Project Wizard (you quickly create and set up all of the basic files you'll need for a new Android application.) It automates and simplifies the process of building your Android application. It provides an Android code editor that helps you write valid XML for your Android manifest and resource files. export project into a signed APK, which can be distributed to users.

Page 29: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

29

DONG NAI UNIVERSITY OF TECHNOLOGY

3.1 Introdution to software tools Android SDK Tools that help you develop mobile applications on the Android platform

Android Development Tools (ADT) Plugin Android Emulator

Device emulation tool that you can use to design, debug, and test your applications in an actual Android run-time environment without an actual phone Android Virtual Devices(AVDs) Virtual device configurations that you create, to model device characteristics in the Android Emulator Each AVD functions as an independent device with it's own storage for user data, SD card, and so on.

Page 30: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

30

DONG NAI UNIVERSITY OF TECHNOLOGY

3.1 Introdution to software tools List of Software Tools

OS: Windows (XP or later), Linux (Ubuntu10.10), Mac OS (10.x or later) Java Development Kit (6 or later) http://java.sun.com/javase/downloads/index.jsp

Android SDK http://developer.android.com/sdk/index.html

Eclipse IDE ADT Plugin for Eclipse IDE

Page 31: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

31

DONG NAI UNIVERSITY OF TECHNOLOGY

3.1 Introdution to software tools Java JDK and JRE

Java Development Kit (JDK) Required to develop applications in Java Contains a Java compiler, debugger, documentation tools, and other tools

Java Runtime Environment (JRE) Allows you to run a Java application

Page 32: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

32

DONG NAI UNIVERSITY OF TECHNOLOGY

3.1 Introdution to software tools Why Eclipse

Integrated development environment (IDE) Similar to Microsoft Visual Studio Not required for Android development Alternatives include

Command-line based tools only Other IDEs, e.g., NetBeans

Google documentation refers to Eclipse extensively

Page 33: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

33

DONG NAI UNIVERSITY OF TECHNOLOGY

3.1 Introdution to software tools The Emulator

Page 34: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

34

DONG NAI UNIVERSITY OF TECHNOLOGY

3.2 Install Android SDK Step 1: Install Java Development Kit

download the JDK from http://java.sun.com/javase/downloads/index.jsp

Step 2: Install Eclipse IDE To download and install Eclipse IDE visit http://www.eclipse.org/downloads/

Step 3: Download the Android SDK Starter Package The Android SDK Starter Package includes the core SDK tools. This helps in downloading and installing the rest of SDK components. download the Starter Package from http://developer.android.com/sdk/index.html Unpack the downloaded .zip file to any suitable location on your computer. (ex: c:\android-sdk-windows)

Page 35: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

35

DONG NAI UNIVERSITY OF TECHNOLOGY

3.2 Install Android SDK

Step 4: Install ADT Plugin for Eclipse To work with Eclipse IDE you need to install Android Development Tool (ADT). To install this plugin Start Eclipse and select Help -> Install New Software-> Click Add button -> Type URL http://dl-ssl.google.com/android/eclipse/ for Location. In the Available Softwares dialog, select the Developer Tools to install the Android DDMS and Android development Tools.

Page 36: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

36

DONG NAI UNIVERSITY OF TECHNOLOGY

3.2 Install Android SDK

Step 5: Set Android Preferences In Eclipse IDE, select Window -> Preferences. Select Android and browse to the location where Android SDK was unpacked. Press OK button.

Page 37: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

37

DONG NAI UNIVERSITY OF TECHNOLOGY

3.2 Install Android SDK

Step 6: Add SDK Components and APIs Android SDK and AVD Manager is used to add or update the SDK Components and APIs. In Eclipse IDE, select Window -> Android SDK Manager -> Available Packages. Select the APIs you need to develop your applications.

Page 38: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

38

DONG NAI UNIVERSITY OF TECHNOLOGY

3.2 Install Android SDK

Step 6: Add SDK Components and APIs

Page 39: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

39

DONG NAI UNIVERSITY OF TECHNOLOGY

3.2 Install Android SDK

Step 7: Create Virtual Devices To run the emulator to run applications, you need to create Virtual Devices. You can create multiple devices each with different configurations as per your need. To define an AVD, in Eclipse IDE,select Window ->

Android Virtual Devices Manager. Press New button and define theconfiguration for your new virtual device.

Page 40: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

40

DONG NAI UNIVERSITY OF TECHNOLOGY

3.2 Install Android SDK

Step 7: Create Virtual Devices

Page 41: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

41

DONG NAI UNIVERSITY OF TECHNOLOGY

3.2 Install Android SDK

http://developer.android.com/sdk/installing/index.html

Read more

Page 42: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

42

DONG NAI UNIVERSITY OF TECHNOLOGY

4. Introduction to Android OS

4.1 Reasons to go mobile application development

4.2 Introduction to Android

4.3 Background History

4.4 What is Open Handset Alliance?

4.5 Android vs Iphone

4.6 Android components

Page 43: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

43

DONG NAI UNIVERSITY OF TECHNOLOGY

4.1 Reasons to go mobile application development

Smart Phones Internet access anywhere Social networking

Millions of mobile users Open standards

Page 44: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

44

DONG NAI UNIVERSITY OF TECHNOLOGY

Open software platform for mobile development created by Google and the Open Handset Alliance.

A complete stack – OS, Middleware, Applications, a large market Powered by Linux operating system Fast application development in Java Open source under the Apache 2 license

4.2 Introduction to Android

Page 45: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

45

DONG NAI UNIVERSITY OF TECHNOLOGY

4.3 Background History

There exists a great variety of mobile operating systems: Symbian OS, MS Windows Mobile, Mobile Linux, iPhone OS, Moblin… Great market fragmentation So far no single OS has become the defact to standard (there will ever be one mobile OS; more likely two or three major mobile OS's and a few minor ones)

Page 46: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

46

DONG NAI UNIVERSITY OF TECHNOLOGY

4.3 Background History

In 2005, Google acquires the startup company Android, Inc. In 2005, the work begins on the Dalvik VM and other components of the Android Platform In 2007, the Open Handset Alliance is formed by a group of companies(Sprint, Motorola, Samsung, Sony Ericsson, Google, Intel, Texas Instruments, etc…)

Page 47: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

47

DONG NAI UNIVERSITY OF TECHNOLOGY

4.3 Background History

The Open Handset Alliance releases a lot of IP through the Apache License, Version2.0 In Nov.2007, the first version of the Android SDK is released In Sept.2008, T-Mobile G1 becomes the 1st

smartphone with the Android platform (ver 1.0)In Feb.2009, Android 1.1 is releasedIn Apr.2009, Android 1.5 Cupcake is releasedIn Sept.2009, Android 1.6 Donut is released In Oct.2009, Android 2.0 Eclair is releasedIn Jan.2010, Android 2.1 Eclair is released

Page 48: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

48

DONG NAI UNIVERSITY OF TECHNOLOGY

4.3 Background History

In May.2010, Android 2.2.x Froyo is released In Dec.2010, Android 2.3.x Gingerbread is releasedIn Feb.2011, Android 3.x Honeycomb Froyo is releasedIn Oct.2011, Android 4.0.x Ice Cream Sandwich is releasedIn Jul.2012, Android 4.1 Jelly Bean is releasedIn Nov.2012, Android 4.2 Jelly Bean is releasedIn July.2013, Android 4.3 Jelly Bean is releasedThe next Android 4.4 KitKat

Page 49: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

49

DONG NAI UNIVERSITY OF TECHNOLOGY

4.3 Background History

Sept.2008

Feb.2009

Apr.2009

Oct.2009

May.2010

Dec.2010

Page 50: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

50

DONG NAI UNIVERSITY OF TECHNOLOGY

4.3 Background History

Feb.2011

Oct.2011

Jul.2012

Nov.2012

Page 51: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

51

DONG NAI UNIVERSITY OF TECHNOLOGY

4.3 Background History

24 July 2013

http://en.wikipedia.org/wiki/Android_version_history

Android 4.4 KitKat

(API level 19)

Page 52: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

52

DONG NAI UNIVERSITY OF TECHNOLOGY

4.4 What is Open Handset Alliance?

a group of 47 (Maybe now >47) technology and mobile companies have come together to accelerate innovation in mobile and offer consumers a richer, less expensive, and better mobile experience. developed Android™, the first complete, open, and free mobile platform. commercial deploy handsets and services using the Android Platform.

Page 53: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

DONG NAI UNIVERSITY OF TECHNOLOGY

53

4.4 What is Open Handset Alliance?

http://en.wikipedia.org/wiki/Open_Handset_Alliance

Open Handset Alliance Members

Page 54: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

54

DONG NAI UNIVERSITY OF TECHNOLOGY

4.5 Android vs Iphone Android Iphone

Operating Systems: Android apps can be developed on Windows ,Linux ,and MacOS

iPhone apps only on a Mac

Programming Languages: Android apps can be developed in Java, C/C++, and increasingly in Python and Perl

Objective C is the only choice for serious iPhone development for now

Source Code Availability: Android is mostly open source iPhone is 100% proprietary

Third-party Software Distribution: There is a small entry fee for publishing Android apps on the Android market

there is an Apple-centered certification process to make your apps available in the AppStore

Different Philosophies: Bottom-up openness Top-down quality control

Page 55: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

55

DONG NAI UNIVERSITY OF TECHNOLOGY

4.5 Android vs Iphone

Hardware Choices: Dual-Core CPU, Camera, Audio device, Bigger Screens… Pricing Java for developers Accessibility: Your Choice of Carriers. several different devices manufacturers like HTC, Motorola and Samsung. They are also available with a choice of carriers and different plans to suit different users' needs

So, why Android?

Page 56: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

56

DONG NAI UNIVERSITY OF TECHNOLOGY

4.6 Android components

Application framework enabling reuse and replacement of components Dalvik virtual machine optimized for mobile devices Integrated browser based on the open source WebKit engine Optimized graphics powered by a custom 2D graphics library; 3D graphics based on the OpenGL ES specification (hardware acceleration optional) SQLite for structured data storage Media support for common audio, video, and still image formats (MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, GIF) GSM Telephony (hardware dependent) Bluetooth, EDGE, 3G, 4G, and Wi-Fi (hardware dependent) Camera, GPS, compass, and accelerometer (hardware dependent) Rich development environment including a device emulator, tools for debugging, memory and performance profiling, and a plugin for the Eclipse IDE

Page 57: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

57

DONG NAI UNIVERSITY OF TECHNOLOGY

4.6 Android components

Android Software Stack

Page 58: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

58

DONG NAI UNIVERSITY OF TECHNOLOGY

4.6 Android components

Linux kernel is a proven core platform. Reliability is more important than performance when it comes to a mobile phone, because voice communication is the primary use of a phone. Linux provides a hardware abstraction layer, letting the upper levels remain unchanged despite changes in the underlying hardware. As new accessories appear on the market, drivers can be written at the Linux level to provide support, just as on other Linux platforms.

Why use Linux for a phone?

Page 59: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

59

DONG NAI UNIVERSITY OF TECHNOLOGY

4.6 Android components

Page 60: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

60

DONG NAI UNIVERSITY OF TECHNOLOGY

4.6 Android components

Linux Kernel •Works as a HAL •Device drivers •Memory management •Process management •Networking

Page 61: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

61

DONG NAI UNIVERSITY OF TECHNOLOGY

4.6 Android components

Libraries

•C/C++ libraries •Interface through Java •Surface manager – Handling UI Windows •2D and 3D graphics •Media codecs, SQLite, Browser engine

Page 62: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

62

DONG NAI UNIVERSITY OF TECHNOLOGY

4.6 Android components

Android Runtime •Dalvik VM –Dex files –Compact and efficient than class files –Limited memory and battery power •Core Libraries –Java 5 Std edition –Collections, I/O etc…

Page 63: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

63

DONG NAI UNIVERSITY OF TECHNOLOGY

4.6 Android components

Application Framework •API interface •Activity manager – manages application life cycle.

Page 64: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

64

DONG NAI UNIVERSITY OF TECHNOLOGY

4.6 Android components

Application•Built in and user apps •Can replace built in apps

Page 65: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

65

DONG NAI UNIVERSITY OF TECHNOLOGY

4.6 Android components

Dalvik Virtual Machine

Dalvik is the name of a town in Iceland Dalvik VM is written by Daniel Bornstein Dalvik VM takes the generated .class files and combines them in to one or more .dex files (Dalvik executables) It reuses the information from .class files to reduce the size of the footprint Dalvik VM uses the registers as the primary source of data storage in stead of the stack (JVM)

Page 66: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

66

DONG NAI UNIVERSITY OF TECHNOLOGY

4.6 Android components

Android applications are compiled to Dalvik bytecode

Page 67: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

67

DONG NAI UNIVERSITY OF TECHNOLOGY

4.6 Android components

The Dalvik runtime is optimised for mobile applications

Page 68: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

68

DONG NAI UNIVERSITY OF TECHNOLOGY

5. Using Android OS / Devices

5.1 Creating Android device without Buying a Phone

5.2 Using Android device

5.3 Using Android virtual device

5.4 Connect and debug on real device

Page 69: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

69

DONG NAI UNIVERSITY OF TECHNOLOGY

5.1 Creating Android device without Buying a Phone

Creating Android Virtual Device Setup account: contact, email Using market from AVD

Page 70: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

70

DONG NAI UNIVERSITY OF TECHNOLOGY

5.2 Using Android device

Page 71: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

71

DONG NAI UNIVERSITY OF TECHNOLOGY

5.2 Using Android device Android Desktops Call, SMS, Contact, Calendar, Email Gallery, play audio, video file Change desktop, add widget, copy shortcut to desktop Using button: home, back, menu Copy/Paste text between apps Setting Using web browser Application: Install /Uninstall/Move to SD card Market Apk file Talk manager Notification SD card / unmount SD card

Page 72: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

72

DONG NAI UNIVERSITY OF TECHNOLOGY

5.3 Using Android virtual device

Ver 1.5

Page 73: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

73

DONG NAI UNIVERSITY OF TECHNOLOGY

5.3 Using Android virtual device

Ver 1.6

Page 74: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

74

DONG NAI UNIVERSITY OF TECHNOLOGY

5.3 Using Android virtual device

Ver 4.0

Page 75: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

75

DONG NAI UNIVERSITY OF TECHNOLOGY

5.3 Using Android virtual device

http://developer.android.com/tools/help/emulator.html

Page 76: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

76

DONG NAI UNIVERSITY OF TECHNOLOGY

5.3 Using Android virtual device

Change Android emulator skin Copy folder in to flatform

Emulator vs Simulator VirtualPC or Vmware?

Page 77: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

77

DONG NAI UNIVERSITY OF TECHNOLOGY

5.3 Using Android virtual device

Emulator looks for the disk images in the private storage area of the AVD in use

Page 78: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

78

DONG NAI UNIVERSITY OF TECHNOLOGY

5.3 Using Android virtual device

The default storage location for AVDs is in Users\<user>\.android\avd\

Page 79: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

79

DONG NAI UNIVERSITY OF TECHNOLOGY

5.3 Using Android virtual device

android list targets (android-skd\tools) android list avd emulator -avd<avd_name> adb devices adb shell

Log in AVD shell (1) adb –s emulator-5554 shell telnet localhost 5554

smssend <Sender’s phone number> <text message> gsmcall <caller’s phone number>

You must setup Environment variables to use adb command line

Page 80: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

80

DONG NAI UNIVERSITY OF TECHNOLOGY

5.3 Using Android virtual device

accepts a number of Linux shell commands in Android Emulator:

Page 81: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

81

DONG NAI UNIVERSITY OF TECHNOLOGY

5.3 Using Android virtual device DDMS – Emulator Control

Page 82: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

82

DONG NAI UNIVERSITY OF TECHNOLOGY

5.3 Using Android virtual device DDMS-File Explorer

Page 83: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

83

DONG NAI UNIVERSITY OF TECHNOLOGY

5.3 Using Android virtual device

3G icon on AVD Path data/data (permission) on File Explorer in DDMS Send sms from 2 AVDs Copy image/media file to AVD Capture screen Change screen orientation for AVD

Ctrl + F11

Volume Ctrl +F5, Ctrl + F6

Full Screen Alt + Enter

Page 84: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

84

DONG NAI UNIVERSITY OF TECHNOLOGY

5.4 Connect and debug on real device

Install from unknown source USB mode Setting debug mode ADB driver Debug in eclipse

Page 85: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

85

DONG NAI UNIVERSITY OF TECHNOLOGY

6. Eclipse debug with Android app

<application android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:debuggable="true">

Page 86: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

86

DONG NAI UNIVERSITY OF TECHNOLOGY

7. Components of the Android Application

7.1 View

7.2 Activity

7.3 Intent / IntentFilters

7.8 Android Application

7.4 Content Provider

7.5 Services

7.6 Broadcast Receiver

7.7 AndroidManifest.xml

Page 87: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

87

DONG NAI UNIVERSITY OF TECHNOLOGY

7.1 View

A View is a UI building block: a text field, a label, a button, … Views are hierarchical objects that know how to draw themselves J2EE and Swing use the same term-view In MS GUI lingo, views are controls

Page 88: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

88

DONG NAI UNIVERSITY OF TECHNOLOGY

7.2 Activity

An Activity is a single screen in an application An Activity typically contains at least one view An application may have several activities

Page 89: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

89

DONG NAI UNIVERSITY OF TECHNOLOGY

7.3 Intent / IntentFilters

A Message object that announces an intention An Intent can broadcast a message An Intent can start a service An Intent can launch an activity Intents are initiated by applications

Intent

Page 90: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

90

DONG NAI UNIVERSITY OF TECHNOLOGY

7.3 Intent / IntentFilters

IntentFiltersAn Intent is a declaration of need. An Intent is made up of various pieces including: –desired action or service, –data, and –category of component that should handle the intent and instructions on how to launch a target activity. An IntentFilter is a trigger, a declaration of capability and interest in offering assistance to those in need. An IntentFilter may be generic or specific with respect to which Intents it offers to service.

Page 91: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

91

DONG NAI UNIVERSITY OF TECHNOLOGY

7.4 Content Provider

A Mechanism (essentially, an API) for applications to share data without exposing the underlying storage details The underlying data can be stored in a file or a database

Page 92: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

92

DONG NAI UNIVERSITY OF TECHNOLOGY

7.5 Services

A Background process not interacting with the user for an indefinite period of time. like other application objects, run in the main thread of their hosting process

Example: an email application that polls for new message

Local services are services accessible to the hosting application Remote services are services that can be used by other applications on the device

Page 93: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

93

DONG NAI UNIVERSITY OF TECHNOLOGY

7.6 Broadcast Receiver

If an application wants to receive and respond to a global event, such as the phone ringing or an incoming text message, it must register as a BroadcastReceiver.

An application may register at runtime Or register at the AndroidManfest.xml file

it does not have to be running When the global event occurs, the application is started automatically upon notification of the triggering event. All of this housekeeping is managed by the Android OS itself. do not have a UI

Page 94: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

94

DONG NAI UNIVERSITY OF TECHNOLOGY

7.7 AndroidManifest.xml

An XML file that defines the contents and behavior of the application It names the Java package for the application. (unique identifier for the application.) It declares the minimum level of the Android API that the application requires. It contains the list of activities in the application It describes the components of the application —the activities, services, broadcast receivers, and content providers

Page 95: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

95

DONG NAI UNIVERSITY OF TECHNOLOGY

7.7 AndroidManifest.xml

It declares IntentFilter. It declares which permissions the application must have in order to access protected parts of the API and interact with other applications. It also declares the permissions that others are required to have in order to interact with the application's components. It lists the libraries that the application must be linked against. ….

Page 96: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

96

DONG NAI UNIVERSITY OF TECHNOLOGY

7.8 Android Application Activities, services, BroadcastReceivers, ContentProviders,Go Here

Auto gen

Android libs

Resource

Layout

Manifest

Page 97: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

97

DONG NAI UNIVERSITY OF TECHNOLOGY

8. Units of measurement

8.1 Screen

8.2 Units of measurement

8.3 Example

http://developer.android.com/guide/practices/screens_support.html

Please visit the link below to get more information about Units of Measurement:

Page 98: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

98

DONG NAI UNIVERSITY OF TECHNOLOGY

8.1 Screen

Screen size: Actual physical size, measured as the screen's diagonal: small, normal, large, and extra large Screen density: The quantity of pixels within a physical area of the screen - dpi (dots per inch): low, medium, high, and extra high. Orientation: landscape or portrait Resolution: The total number of physical pixels on a screen.

app do not work directly with resolution; concerned only with screen size and density

Page 99: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

99

DONG NAI UNIVERSITY OF TECHNOLOGY

8.1 Screen

Density-independent pixel (dp) : A virtual pixel unit that you should use when defining UI layout, to express layout dimensions or position in a density-independent way.

Page 100: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

100

DONG NAI UNIVERSITY OF TECHNOLOGY

8.2 Units of measurement

In Inches - based on the physical size of the screen

Mm Millimeters - based on the physical size of the screen.

Pt Points - 1/72 of an inch based on the physical size of the screen.

Px Pixels - corresponds to actual pixels on the screen

Dip /Dp Density-independent Pixels - an abstract unit that is based on the physical density of the screen. These units are relative to a 160 dpi screen, so one dp is one pixel on a 160 dpi screen. The ratio of dp-to-pixel will change with the screen density, but not necessarily in direct proportion.

Sp/sip Scale-independent Pixels - this is like the dp unit, but it is also scaled by the user's font size preference. It is recommend you use this unit when specifying font sizes, so they will be adjusted for both the screen density and user's preference.

Page 101: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

101

DONG NAI UNIVERSITY OF TECHNOLOGY

8.2 Units of measurement

try to never use anything but sp or dp unless you absolutely have to. Using sp/dp will make your Android applications compatible with multiple screen densities and resolutions you want to use sp for font sizes and dip for everything else.

Page 102: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

102

DONG NAI UNIVERSITY OF TECHNOLOGY

8.3 Example

Example of two screens that are the same size, diff resolution:

Page 103: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

103

DONG NAI UNIVERSITY OF TECHNOLOGY

8.3 Example

app without support for different densities vs density independent

Page 104: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

104

DONG NAI UNIVERSITY OF TECHNOLOGY

http://developer.android.com/about/dashboards/index.html

Screen Sizes and Densities distribution:

Data collected during a 7-day period ending on September 4, 2013

Page 105: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

105

DONG NAI UNIVERSITY OF TECHNOLOGY

http://developer.android.com/about/dashboards/index.html

Platform version distribution:

Page 106: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

106

DONG NAI UNIVERSITY OF TECHNOLOGY

9. XML Primer

XML in Android: Layout, Menu, Value, Manifest …

http://www.w3schools.com/ Please visit the link below to learn more XML:

http://developer.android.com/training/basics/network-ops/xml.html

Please visit the link below to parse xml data:

Page 107: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

107

DONG NAI UNIVERSITY OF TECHNOLOGY

10. Application’s Life Cycle

10.1 Applications

10.2 Activities

10.3 Activity Stack

10.4 Tasks

10.5 Life Cycle States

Page 108: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

108

DONG NAI UNIVERSITY OF TECHNOLOGY

10.1 Applications

typically consists of one or more related, loosely bound activities for the user to interact with, typically bundled up in a single file (with an .apk suffix). Android ships with a rich set of applications:email, calendar, browser, maps, text messaging, contacts, camera, dialer, music player…. Android has an application launcher available at the Home screen

Page 109: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

109

DONG NAI UNIVERSITY OF TECHNOLOGY

10.2 Activities

main building blocks of Android applications Each activity has a lifecycle that is independent of the other activities in its application or task each activity is launched (started) independently, user or system can start, run, pause, resume, stop and restart it as needed. can be re-used and replaced by other activities in a variety of ways.

Page 110: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

110

DONG NAI UNIVERSITY OF TECHNOLOGY

10.3 Activity Stack

Activities in the system are managed as an activity stack. keeps a linear navigation history of activities the user has visited when a user starts a new activity, it is added to the activity stack, so that pressing Back displays the previous activity on the stack. However, the user cannot use the Back button to go back further than the last visit to Home. Activities are the only things that can be added to the activity stack — views, windows, menus, and dialogs cannot.

Page 111: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

111

DONG NAI UNIVERSITY OF TECHNOLOGY

10.3 Activity Stack

Page 112: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

112

DONG NAI UNIVERSITY OF TECHNOLOGY

10.4 Tasks

sequence of activities the user follows to accomplish an objective, regardless of which applications the activities belong to The activity that starts a task is called the root activity spanning multiple processes Interrupting the Task

by a notification Home button

How Multitasking with Task?

Page 113: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

113

DONG NAI UNIVERSITY OF TECHNOLOGY

Activities vs Task

Page 114: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

114

DONG NAI UNIVERSITY OF TECHNOLOGY

10.5 Life Cycle States

An activity has essentially three states:

1. It is active or running 2. It is paused or 3. It is stopped .

Page 115: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

115

DONG NAI UNIVERSITY OF TECHNOLOGY

10.5 Life Cycle States

Running It is active or running when it is in the foreground of the screen (at the top of the activity stack for the current task). This is the activity that is the focus for the user's actions.

Page 116: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

116

DONG NAI UNIVERSITY OF TECHNOLOGY

10.5 Life Cycle States

Paused It is paused if it has lost focus but is still visible to the user. That is, another activity lies on top of it and that new activity either is transparent or doesn't cover the full screen. A paused activity is completely alive (it maintains all state and member information and remains attached to the window manager), but can be killed by the system in extreme low memory situations.

Page 117: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

117

DONG NAI UNIVERSITY OF TECHNOLOGY

10.5 Life Cycle States

Stopped It is stopped if it is completely obscured by another activity. It still retains all state and member information. However, it is no longer visible to the user so its window is hidden and it will often be killed by the system when memory is needed elsewhere.

Page 118: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

118

DONG NAI UNIVERSITY OF TECHNOLOGY

10.5 Life Cycle States

Application’s Life Cycle

Page 119: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

119

DONG NAI UNIVERSITY OF TECHNOLOGY

10.5 Life Cycle States

DemoApplication’s Life Cycle

Page 120: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

120

DONG NAI UNIVERSITY OF TECHNOLOGY

10.5 Life Cycle States

Visible Lifetime

Foreground Lifetime

Page 121: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

121

DONG NAI UNIVERSITY OF TECHNOLOGY

10.5 Life Cycle States Visible Lifetime

The visible lifetime of an activity happens between a call to onStart() until a corresponding call to onStop(). During this time, the user can see the activity on‐screen, though it may not be in the foreground and interacting with the user. The onStart() and onStop() methods can be called multiple times, as the activity alternates between being visible and hidden to the user. Between these two methods, you can maintain resources that are needed to show the activity to the user.

Page 122: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

122

DONG NAI UNIVERSITY OF TECHNOLOGY

10.5 Life Cycle States Foreground Lifetime

The foreground lifetime of an activity happens between a call to onResume() until a corresponding call to onPause(). During this time, the activity is in front of all other activities on screen and is interacting with the user. An activity can frequently transition between the resumed and paused states — for example,

onPause() is called when the device goes to sleep or when a new activity is started, onResume() is called when an activity result or a new intent is delivered.

Page 123: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

123

DONG NAI UNIVERSITY OF TECHNOLOGY

10.5 Life Cycle States

Method: onCreate() Called when the activity is first created. This is where you should do all of your normal static set up —create views, bind data to lists, and so on. This method is passed a Bundle object containing the activity's previous state, if that state was captured. Always followed by onStart()

Page 124: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

124

DONG NAI UNIVERSITY OF TECHNOLOGY

10.5 Life Cycle States

Method: onRestart() Called after the activity has been stopped, just prior to it being started again. Always followed by onStart()

Method: onStart() Called just before the activity becomes visible to the user. Followed by onResume() if the activity comes to the foreground, or onStop() if it becomes hidden.

Page 125: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

125

DONG NAI UNIVERSITY OF TECHNOLOGY

10.5 Life Cycle States

Method: onResume() 1. Called just before the activity starts interacting with the user. 2. At this point the activity is at the top of the activity stack, with user input going to it. 3. Always followed by onPause().

Page 126: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

126

DONG NAI UNIVERSITY OF TECHNOLOGY

10.5 Life Cycle States

Method: onPause() 1. Called when the system is about to start resuming another activity. 2. This method is typically used to commit unsaved changes to persistent data, stop animations and other things that may be consuming CPU, and so on. 3. It should do whatever it does very quickly, because the next activity will not be resumed until it returns. 4. Followed either by onResume() if the activity returns back to the front, or by onStop() if it becomes invisible to the user. 5. The activity in this state is killable by the system.

Page 127: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

127

DONG NAI UNIVERSITY OF TECHNOLOGY

10.5 Life Cycle States

Method: onStop() 1. Called when the activity is no longer visible to the user. 2. This may happen because it is being destroyed, or because another activity (either an existing one or a new one) has been resumed and is covering it. 3. Followed either by onRestart() if the activity is coming back to interact with the user, or by onDestroy() if this activity is going away. 4. The activity in this state is killable by the system.

Page 128: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

128

DONG NAI UNIVERSITY OF TECHNOLOGY

10.5 Life Cycle States

Method: onDestroy() 1. Called before the activity is destroyed. 2. This is the final call that the activity will receive. 3. It could be called either because the activity is finishing (someone called finish() on it), or because the system is temporarily destroying this instance of the activity to save space. 4. The activity in this state is killable by the system.

Page 129: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

129

DONG NAI UNIVERSITY OF TECHNOLOGY

10.5 Life Cycle States

Killable States Activities on killable states can be terminated by the system at any time after the method returns, without executing another line of the activity's code. Three methods (onPause(), onStop(), and onDestroy()) are killable. onPause() is the only one that is guaranteed to be called before the process is killed —onStop() and onDestroy() may not be. Therefore, you should use onPause() to write any persistent data (such as user edits) to storage.

Page 130: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

130

DONG NAI UNIVERSITY OF TECHNOLOGY

10.5 Life Cycle States

We should write and read data for application’s sate in methods:onPause() and (onCreate() or onResume()) by SharedPreferences

Page 131: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

131

DONG NAI UNIVERSITY OF TECHNOLOGY

10.5 Life Cycle States Android Preferences Preferences is a lightweight mechanism to store and retrieve key‐value pairs of primitive data types. It is typically used to store application preferences, such as a default greeting or a text font to be loaded whenever the application is started. Call Context.getSharedPreferences() to read and write values. Assign a name to your set of preferences if you want to share them with other components in the same application, or use Activity.getPreferences() with no name to keep them private to the calling activity.

getSharedPreferences() - can be used while using multiple preference files and getPreferences() - can be used for only one preference file(default) for that specific activity. File xml

You cannot share preferences across applications (except by using a content provider).

Page 132: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

132

DONG NAI UNIVERSITY OF TECHNOLOGY

Page 133: 1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động

133

DONG NAI UNIVERSITY OF TECHNOLOGY

END