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
4T025-1-A @ Peter Lo 2014 2Course Outline
3 4T025-1-A @ Peter Lo 2014Lesson 1
Introduction to Android Development
Lesson 2
Android Layout and Components
Lesson 3
Android Life Cycle and Permission
Lesson 4
Menu, Action Bar and Dialog
Lesson 5
Intent and Fragment
Lesson 6
List and Deployment
What Apps can you develop after this course?
Are you take the Right Course?
5
This course is intended for beginner who would
like to learn how to develop Android Apps.
The code examples are not particularly complex,
but it is assumed that you have basic
programming knowledge.
4T025-1-A @ Peter Lo 2014
Where can you find the material?
6
Workshop Notes and Exercises
http://www.Peter-Lo.com/Teaching/4T025-1-A/
Android Developer Official Site
http://developer.android.com/
Microsoft DreamSpark
http://www.dreamspark.com
4T025-1-A @ Peter Lo 2014
Mobile Phone Evolution
7 4T025-1-A @ Peter Lo 2014
What is Android?
8 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.
Android Family
9 4T025-1-A @ Peter Lo 2014 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
10 4T025-1-A @ Peter Lo 2014 Source: http://developer.android.com/about/dashboards/index.htmlScreen Sizes and Densities
Development Process for Android Apps
13 4T025-1-A @ Peter Lo 2014
Creating new Android Project
14 4T025-1-A @ Peter Lo 2014
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)
4T025-1-A @ Peter Lo 2014 15
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 the hierarchical structure of layouts and elements added to the screen. File structure Selector bar
Structure of a Typical Android App
16 4T025-1-A @ Peter Lo 2014
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
Structure of a Typical Android App (cont.)
17 4T025-1-A @ Peter Lo 2014
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
18 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.
4T025-1-A @ Peter Lo 2014
Apps must declare all its components in this file, which must be at the root of the application project directory.
SDK Manager
19 4T025-1-A @ Peter Lo 2014
Simple Android App Program
20 4T025-1-A @ Peter Lo 2014 package com.example.myfirstapp; import android.os.Bundle; import android.app.Activity; import android.view.Menu;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); }
@Override
public 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.
Running Apps
21 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.
4T025-1-A @ Peter Lo 2014
How to Testing or Running Apps?
22
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
4T025-1-A @ Peter Lo 2014
Android Virtual Devices
23
AVD (Android Virtual Device) is an Android Emulator
configuration that lets you model an actual device by
defining hardware and software options
4T025-1-A @ Peter Lo 2014
Operation of AVD
Debugging
25
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
4T025-1-A @ Peter Lo 2014Log Cat
26The 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.
4T025-1-A @ Peter Lo 2014
Logcat Level
27 4T025-1-A @ Peter Lo 2014
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
Android Debug Bridge (adb)
29 A versatile command line tool that lets you communicate with an emulator instance or connected Android-powered device:
Client, which runs on your development machine. You can invoke a client from a shell by issuing an adb command. Server, which runs as a background process on your development machine.
Daemon, which runs as a background process on each emulator or device instance.
You can find the adb tool in <sdk>/platform-tools/.
4T025-1-A @ Peter Lo 2014
Break Point
30