1 - Giới Thiệu Môi Trường Phát Triển Điện Thoại Di Động
-
Upload
ta-van-thanh -
Category
Documents
-
view
222 -
download
0
Transcript of 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
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
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
4
DONG NAI UNIVERSITY OF TECHNOLOGY
1.1 Topics
User Interfaces Views
Layouts
Widgets
UI XML specification
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
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
7
DONG NAI UNIVERSITY OF TECHNOLOGY
1.1 Topics
Common Android APIsNetworking APIsLBS APIs
Web APIsMultimedia APIs
Telephony APIs
And Sensors…
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
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…
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
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
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
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…
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
15
DONG NAI UNIVERSITY OF TECHNOLOGY
1.6 Rules
- Attendance 75%
- Do homework
- Do lab project
- Research on internet
16
DONG NAI UNIVERSITY OF TECHNOLOGY
2. Mobile / Tablet OSs
MobileSymbian
Ubuntu
BlackBerry
Windows Phone
Bada
MeeGo
IOS WebOS
Android
17
DONG NAI UNIVERSITY OF TECHNOLOGY
Bada
Samsung
Closed source
http://developer.bada.com
18
DONG NAI UNIVERSITY OF TECHNOLOGY
C/C++ J2EM
http://www.developer.nokia.com/
19
DONG NAI UNIVERSITY OF TECHNOLOGY
Windows Phone
http://dev.windowsphone.com C#VB.netXAML
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
21
DONG NAI UNIVERSITY OF TECHNOLOGY
IOS Apple
derived from Mac OS X. Objective C – iPhone SDk
https://developer.apple.com
22
DONG NAI UNIVERSITY OF TECHNOLOGY
BlackBerry
https://developer.blackberry.com/
23
DONG NAI UNIVERSITY OF TECHNOLOGY
Android Google Inc
free and open source
Linux-derived OS
Java (Android SDK)
http://developer.android.com/
24
DONG NAI UNIVERSITY OF TECHNOLOGY
Ubuntu
http://www.ubuntu.com/devices/android
Professional Ubuntu Mobile Development
25
DONG NAI UNIVERSITY OF TECHNOLOGY
MeeGoopen source
Nokia + Intel
https://meego.com/developers
C++
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
27
DONG NAI UNIVERSITY OF TECHNOLOGY
3. Software Installation
3.1 Introdution to software tools
3.2 Install Android SDK
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.
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.
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
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
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
33
DONG NAI UNIVERSITY OF TECHNOLOGY
3.1 Introdution to software tools The Emulator
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)
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.
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.
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.
38
DONG NAI UNIVERSITY OF TECHNOLOGY
3.2 Install Android SDK
Step 6: Add SDK Components and APIs
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.
40
DONG NAI UNIVERSITY OF TECHNOLOGY
3.2 Install Android SDK
Step 7: Create Virtual Devices
41
DONG NAI UNIVERSITY OF TECHNOLOGY
3.2 Install Android SDK
http://developer.android.com/sdk/installing/index.html
Read more
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
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
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
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)
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…)
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
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
49
DONG NAI UNIVERSITY OF TECHNOLOGY
4.3 Background History
Sept.2008
Feb.2009
Apr.2009
Oct.2009
May.2010
Dec.2010
50
DONG NAI UNIVERSITY OF TECHNOLOGY
4.3 Background History
Feb.2011
Oct.2011
Jul.2012
Nov.2012
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)
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.
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
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
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?
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
57
DONG NAI UNIVERSITY OF TECHNOLOGY
4.6 Android components
Android Software Stack
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?
59
DONG NAI UNIVERSITY OF TECHNOLOGY
4.6 Android components
60
DONG NAI UNIVERSITY OF TECHNOLOGY
4.6 Android components
Linux Kernel •Works as a HAL •Device drivers •Memory management •Process management •Networking
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
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…
63
DONG NAI UNIVERSITY OF TECHNOLOGY
4.6 Android components
Application Framework •API interface •Activity manager – manages application life cycle.
64
DONG NAI UNIVERSITY OF TECHNOLOGY
4.6 Android components
Application•Built in and user apps •Can replace built in apps
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)
66
DONG NAI UNIVERSITY OF TECHNOLOGY
4.6 Android components
Android applications are compiled to Dalvik bytecode
67
DONG NAI UNIVERSITY OF TECHNOLOGY
4.6 Android components
The Dalvik runtime is optimised for mobile applications
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
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
70
DONG NAI UNIVERSITY OF TECHNOLOGY
5.2 Using Android device
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
72
DONG NAI UNIVERSITY OF TECHNOLOGY
5.3 Using Android virtual device
Ver 1.5
73
DONG NAI UNIVERSITY OF TECHNOLOGY
5.3 Using Android virtual device
Ver 1.6
74
DONG NAI UNIVERSITY OF TECHNOLOGY
5.3 Using Android virtual device
Ver 4.0
75
DONG NAI UNIVERSITY OF TECHNOLOGY
5.3 Using Android virtual device
http://developer.android.com/tools/help/emulator.html
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?
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
78
DONG NAI UNIVERSITY OF TECHNOLOGY
5.3 Using Android virtual device
The default storage location for AVDs is in Users\<user>\.android\avd\
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
80
DONG NAI UNIVERSITY OF TECHNOLOGY
5.3 Using Android virtual device
accepts a number of Linux shell commands in Android Emulator:
81
DONG NAI UNIVERSITY OF TECHNOLOGY
5.3 Using Android virtual device DDMS – Emulator Control
82
DONG NAI UNIVERSITY OF TECHNOLOGY
5.3 Using Android virtual device DDMS-File Explorer
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
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
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">
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
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
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
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
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.
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
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
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
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
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. ….
96
DONG NAI UNIVERSITY OF TECHNOLOGY
7.8 Android Application Activities, services, BroadcastReceivers, ContentProviders,Go Here
Auto gen
Android libs
Resource
Layout
Manifest
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:
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
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.
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.
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.
102
DONG NAI UNIVERSITY OF TECHNOLOGY
8.3 Example
Example of two screens that are the same size, diff resolution:
103
DONG NAI UNIVERSITY OF TECHNOLOGY
8.3 Example
app without support for different densities vs density independent
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
105
DONG NAI UNIVERSITY OF TECHNOLOGY
http://developer.android.com/about/dashboards/index.html
Platform version distribution:
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:
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
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
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.
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.
111
DONG NAI UNIVERSITY OF TECHNOLOGY
10.3 Activity Stack
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?
113
DONG NAI UNIVERSITY OF TECHNOLOGY
Activities vs Task
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 .
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.
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.
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.
118
DONG NAI UNIVERSITY OF TECHNOLOGY
10.5 Life Cycle States
Application’s Life Cycle
119
DONG NAI UNIVERSITY OF TECHNOLOGY
10.5 Life Cycle States
DemoApplication’s Life Cycle
120
DONG NAI UNIVERSITY OF TECHNOLOGY
10.5 Life Cycle States
Visible Lifetime
Foreground Lifetime
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.
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.
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()
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.
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().
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.
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.
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.
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.
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
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).
132
DONG NAI UNIVERSITY OF TECHNOLOGY
133
DONG NAI UNIVERSITY OF TECHNOLOGY
END