Download Android Tutorial

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Introduction to
Android Programming
Contents
• Basic Concepts
• Environment Setup
• Creating and Building Android App
Android
• Android apps are written in Java
• The Android OS is a multi-user Linux system
• Android app lives in its own security sandbox
• System assigns each app a unique Linux user ID
• Each process has its own virtual machine
• Every application runs in its own Linux process
Application Components
• Android Application
• .apk : Android package
• Four Application Components
• Activity
• Service
• Content Provider
• Broadcast Receiver
• Communication among components except Content Provider
• Intent
Activity
• Activity Lifecycle
• Implement Lifecycle Callbacks
Activity
• Start an Activity
• Start an Activity for a Result
• Caller Activity
• Callee Activity
Activities and Stack
Services
• A service is a component that runs in the background to
perform long-running operations
• A service does not provide a user interface
• Activity can start the service and let it run or bind to it
in order to interact with it
e.g., a service might play music in the background while the
user is in a different app
Broadcast Receivers
• A broadcast receiver is a component that responds to
system-wide broadcast announcements
• Apps can also initiate broadcasts
• Although broadcast receivers don't display a UI, they may
create a status bar notification to alert the user when a
broadcast event occurs
Content Providers
• A content provider manages a shared set of app
data
• Through the content provider, other apps can query or even
modify the data
• Any app with the proper permissions can query part of
the content provider
Intent
• An intent is an abstract description of an operation to be
performed
•
•
•
•
startActivity
sendBroadcast
startService (bindService)
…
Environment Setup
Step 1: Install JDK
JDK Installation
• Can download the JDK for your OS at http://java.oracle.com
• Alternatively,
OS X:
• Open "Terminal”
• Type javac at command line
• Install Java when prompt appears
Linux:
• Type sudo apt–get install default–jdk at command line
(Debian, Ubuntu)
• Other distributions: consult the documentation
Environment Setup
Step 2: Configure the Android SDK
SDK Configuration
• Download Android SDK from http://developer.android.com
Or
• Simplest: Download and install Android Studio bundle
(including Android SDK)
• Eclipse IDE- Official IDE for Android development
• Apache Ant for building
projects
Android Studio
• Android Development Environment based on IntelliJ IDEA
Android Studio
• Android uses Gradle
• Gradle is an open source build system that combines
the power of Ant and Maven
Android Studio
Run Android SDK Manager
• Recommended: Install Android 2.2, 2.3.3 APIs and 4.x API
• Do not worry about Intel x86 Atom, MIPS system images
Settings
Now you are ready for
Android development!
Create New Android Project
Create Activity
The Manifest File
• Identify any user permissions the application requires
• Declare the minimum API level required by the application
• Declare hardware and software features used or required
by the application
• API libraries the application needs to be linked
The Manifest File
The Manifest File
• Do not forget to declare Components in the Manifest
Permission
• Add following permissions to the Manifest file
Sample Code
UI – Declaring Layout
• Initiated when called setContentView() on onCreate()
• Use Visual Layout Editor for initial layout design
• Edit XML file extensively
Editing Sample Code
Add id to main.xml
“@+id/helloId”
Edit
HelloWorldActivity.java
A Sample Code
Important points
1
2
3
Hello world!
1. UI Element
has an Id
2. Variables in
our code link
to UI elements
3. Update UI
element
content from
the program
UI – Handling UI Events
• onClick, onLongClick, onKey, onTouch, …
Sample Implementation
Option menu
MainActivity
Context menu
Play click
Capture
CaptureActivity
Upload Service
Capture Button Click
Background Upload
PlayerActivity
Building Process
Running
Running Sample App
App Failure
Debugging, look at DDMS !!!
“Dalvik Debug Monitor Service”
Enabling USB Debugging
Thank You!
Any questions
*These slides are based on the slides from http://www.comp.nus.edu.sg/~cs5248/l03/L3-ProgrammingInAndroid.pdf