android apps development for · 2015-05-08 · android apps development for mobile and tablet...
TRANSCRIPT
ANDROID APPS DEVELOPMENT FOR MOBILE AND TABLET DEVICE (LEVEL I)
Peter Lo
Lecture 1: Introduction to Android Development
Who am I?
Lo Chi Wing, Peter
� Email: [email protected]� Facebook: http://www.facebook.com/PeterLo111
X4-XT-CDP-0251-A @ Peter Lo 2015 2
Course Outline
3X4-XT-CDP-0251-A @ Peter Lo 2015
Lesson 1 Introduction to Android Development
Lesson 2 Android Programming Foundation
Lesson 3 Android Life Cycle and Permission
Lesson 4 Action Bar and Simple List
Lesson 5 Intent and Fragment
Lesson 6 Sensor and Storage
Where can you find the material?
4
� Workshop Notes� http://www.Peter-Lo.com/Teaching/X4-XT-CDP-0251-A/
� Android Developer Official Site� http://developer.android.com/
� Microsoft DreamSpark� http://www.dreamspark.com
X4-XT-CDP-0251-A @ Peter Lo 2015
Mobile Phone Evolution
5X4-XT-CDP-0251-A @ Peter Lo 2015
What is Android?
6
� A Linux-based operating system for mobile devices.
� An open-source project and is distributed free of charge.
� Developed by the Open Handset Alliance and Google Inc.
� Supporting telephony, messaging, emailing, contact management, calendar, entertainment, multimedia experience, location services, mapping, social interaction, etc.
X4-XT-CDP-0251-A @ Peter Lo 2015
Android Family
7X4-XT-CDP-0251-A @ Peter Lo 2015
Android 1.5(2009)
Android 1.6(2009)
Android 2.0/2.1(2009)
Android 2.2(2010)
Android 2.3(2010)
Android 3.0(2011)
Android 4.0(2012)
Android 4.4(2013)
Android 4.1(2012)
Platform Versions
8X4-XT-CDP-0251-A @ Peter Lo 2015
Screen Sizes and Densities
9X4-XT-CDP-0251-A @ Peter Lo 2015
Android Architecture
10X4-XT-CDP-0251-A @ Peter Lo 2015
Development Process for Android Apps
11X4-XT-CDP-0251-A @ Peter Lo 2015
Creating new Android Project
12X4-XT-CDP-0251-A @ Peter Lo 2015
Application Name –name appears on device and title bar
Project Name – name for the Eclipse project
Package Name – Apps on a particular Android device must have unique packages
Minimum Required SDK –minimum Android API level required for the app
Target SDK –Android version that you want to use
Compile With – the platform version against which you will compile your app. (By default, set to the latest version of Android available in your SDK).
Theme – specifies the Android UI style to apply for your app.
Android Developer Tool (ADT)
X4-XT-CDP-0251-A @ Peter Lo 2015 13
Zone where the current layout is
rendered
Palette, where we
can choose different layouts
and for the layout design
Switch from the graphical editor to the XML text editor
Object properties
Tree View of hierarchical structure of layouts and
elements added to the
screen.File structure
Selector bar
Structure of a Typical Android App
14X4-XT-CDP-0251-A @ Peter Lo 2015
Executable generated from compiled classes
Zipped archive file that will be shipped to android device
Zipped application resources
Source file with Activities, Services, Broadcast Receivers, and Content Providers
Provides access to resources (with unique ID) in App
Contain 2 auto generated files that should not be touched
Contains text files, database, and the sort
Contains file built by the ADT
Structure of a Typical Android App (cont.)
15X4-XT-CDP-0251-A @ Peter Lo 2015
API that allows you to use the newest API while remaining backward compatible
The layout folder contains files that define the apps under interface• RelativeLayout• LinearLayout• GridLayout• FrameLayout
drawable folders store image you need at different resolutions
AndroidManifest defines: • App name• App icon• Activities used• Permission required for App• android.intent.action.MAIN define the entry point for App
The Manifest File
16
� Before the Android system can start an application component, the system must know that the component exists by reading the application's AndroidManifest.xml file.
X4-XT-CDP-0251-A @ Peter Lo 2015
Apps must declare all its components in this file, which must be at the root of the application project directory.
SDK Manager
17X4-XT-CDP-0251-A @ Peter Lo 2015
Simple Android App Program
18X4-XT-CDP-0251-A @ Peter Lo 2015
package com.example.myfirstapp;
import android.os.Bundle;import android.app.Activity;import android.view.Menu;
public class MainActivity extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);
}
@Overridepublic boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.main, menu);return true;
}}
Define the Activity for output
Overriding an existing method
Apps are frequently shut down by the device. This lets you remember some info about the previous invocation. You should always call super.onCreate as first line of onCreate.
There is no need to type the import statements by hand. Just use the classes in your code, and when Eclipse marks the line as an error, click on the light bulb at the left, or hit [Ctrl] – [1], then choose to have Eclipse insert the import statements for you.
Comment, all statement after // will not execute
Running Apps
19
� During the build process, your Android projects are compiled and packaged into an .apk file. It contains all of the information necessary to run your application on a device or emulator.
� If you are developing in Eclipse, the ADT plugin incrementally builds your project as you make changes to the source code. Eclipse outputs an .apk file automatically to the bin folder of the project, so you do not have to do anything extra to generate the .apk.
X4-XT-CDP-0251-A @ Peter Lo 2015
How to Testing or Running Apps?
20
� On the Android Emulator:
� Deploy directly from Eclipse during development, do your normal testing here
� On an Android device:
� Deploy from your PC via USB
� Deploy from a Web site
� Deploy via email
� Deploy from the Android Market
X4-XT-CDP-0251-A @ Peter Lo 2015
Android Virtual Devices (AVD)
21
� AVD is an Android Emulator configuration that lets you model an actual device by defining hardware and software options
X4-XT-CDP-0251-A @ Peter Lo 2015
Operation of AVD
22X4-XT-CDP-0251-A @ Peter Lo 2015
Debugging
23
� The Android SDK provides most of the tools that you need to debug your applications. � DDMS (Dalvik Debug Monitor Server)� adb (Android Debug Bridge)� JDWP debugger� Breakpoint� Log
X4-XT-CDP-0251-A @ Peter Lo 2015
Log Cat
24
� The Android logging system provides a mechanism for collecting and viewing system debug output.
� Logs from various applications and portions of the system are collected in a series of circular buffers, which then can be viewed and filtered by the logcat command.
X4-XT-CDP-0251-A @ Peter Lo 2015
Logcat Level
25X4-XT-CDP-0251-A @ Peter Lo 2015
Priority Meaning Description
V Verbose Lowest priority. Used for low level debugging. Print stuff like position of your character when you are debugging why the hell it's going off screen etc.
D Debug Messages that could be useful to determine where something went wrong. E.g. put a debug level message to each method beginning and end.
I Info These messages can be useful in production as well. Log important events in info level, e.g. Engine created
W Warning Something not quite right, but it's not a bug. E.g. you can't connect to Facebook to submit High score - not nice, but you can live with it.
E Error Log exceptions and errors that you will need to analyze later and solve.
F Fatal Fatal exception
S Silent Highest priority, on which nothing is ever printed
Dalvik Debug Monitor Service (DDMS)
� DDMS (Dalvik Debug Monitor Service) is a tool that supports many things
� Simulate incoming calls in emulator
� Set GPS locations in emulator
� See print statements and runtime errors
� Set locations and take screenshots of actual Android device
X4-XT-CDP-0251-A @ Peter Lo 2015 26
Break Point
27
� To create a break point, just double click the vertical bar in Java source code
� When you run the application in debug mode, the emulator will pause and you will be able to examine your live code in this mode in the Eclipse debugger.
X4-XT-CDP-0251-A @ Peter Lo 2015