Download android programming - Iowa State University computer science

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
ANDROID
PROGRAMMING
MODULE 1 – GETTING STARTED
DEPARTMENT OF COMPUTER SCIENCE
IOWA STATE UNIVERSITY
 Concepts
 Android OS
 Android Programming
 Setting up the development environment.
ROADMAP
 ADT
 Eclipse IDE
 SKD Manager
 Creating an Android Project
 More Concepts
 Activity
 Basic Structure of an Android Project
 Deployment
 Android OS
 Android is an operating system based on the Linux kernel, and
designed primarily for touchscreen mobile devices such as
smartphones and tablet computers.
 Android is open source and Google releases the source code under
the Apache License.
Concepts
 Android Programming
 Applications are usually developed in the Java programming
language using the Android Software Development Kit, but other
development tools are also available.
Setting up the
Development
Environment
Download
 The Development Environment for Android Contains the following
Components:
 Android Software Development Kit (SDK)
 Android Development Tool Plugin (ADT Plugin)
 Eclipse Integrated Development Environment (IDE) or some other
IDE.
 Google also provides an SDK Manager to Keep the SDK up to date.
 To get these components go to
http://developer.android.com/sdk/index.html and download the
entire package including Eclipse for convenience.
 There are other options for development like the android studio
IDE for developing Android Projects. You can use any tool you are
convenient with, however in the modules Eclipse with ADT Plugin
is used.
 After Downloading the Package and extracting it. You will see that
there are three items:
Setting up the
Development
Environment
Android SDK and SDK
Manager
 The Android SDK is composed of modular packages that you can
download separately using the Android SDK Manager. For
example, when the SDK Tools are updated or a new version of the
Android platform is released, you can use the SDK Manager to
quickly download them to your environment.
 Open the Eclipse folder which contains the Eclipse IDE files and
click on the Application file named Eclipse.
Setting up the
Development
Environment
Eclipse IDE with ADT
Plugin
 The first time one open’s the IDE, it requests to create a work
space. Browse and select the folder to create the workspace
where your projects will be saved.
 Now the Workbench Opens and one can see the Java Perspective
set by default in the top right corner of the window.
Java Perspective
Creating an
Android
Project
 To Create a new Android Project follow these steps.
 Select File -> New -> Android Application Project.
 In the New Android Application Dialog, provide the application
name and package name and click next. One can leave the SDK
versions unmodified for this project.
Creating an
Android
Project
Application and
Package Names
Creating an
Android
Project
Configure Project
 For the First Example Click Next in
all the consecutive windows.
 The Configure Project Window
provides the option of creating a
custom launcher Icon for your App
and create the Main Activity for your
Application.
 The Main Activity is the point of
entry into the application. Unlike
other programming paradigms in
which apps are launched with a
main() method, the Android system
initiates code in an Activity instance
by invoking specific callback
methods that correspond to specific
stages of its lifecycle.
 Click Next in the Configure
Attribute for the icon art window
Creating an
Android
Project
Icon and Activity
 In the Create Activity Window
select Blank Activity and Click
Next. A Blank Activity will be
created in the project which
display’s a “Hello World” string.
 Give a name for your blank
activity in the Blank Activity
Window and Click Finish.
 You have just created an android Project. But before deploying it
in a Mobile Phone or an Emulator, let us look at the structure of
the project created.
Creating an
Android
Project
Contents
of Project
 src : Contains source files and packages.
 gen: Contains files generated on building the project.
Structure of
the Android
Project
 bin: Contains class files and the generated Application
Package (apk) file.
 libs: Contains external libraries
 res: Contains resourses such as drawable , strings ,
layout and other resouses used by the application in the
form of xml files.
 Android Manifest.xml : The manifest presents essential
information about the application to the Android
system, information the system must have before it can
run any of the application's code.
Android
Manifest.xml
The manifest does the following:
 It names the Java package for the application. The package name serves as
a unique identifier for the application.
 It describes the components of the application — the activities, services,
broadcast receivers, and content providers that the application is
composed of. It names the classes that implement each of the
components and publishes their capabilities.
 It declares which permissions the application must have in order to access
protected parts of the API and interact with other applications.
Eg: <uses-permission android:name="android.permission.INTERNET"/>
 It declares the minimum level of the Android API that the application
requires.
Eg: <uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
 It lists the libraries that the application must be linked against.
There are two ways to deploy an application, the first is using a physical
device and the second is to run the application on a virtual device.
Two Ways of
Debugging
Android Virtual Device
Physical Device
Does not support operations which
require accessing the physical ports
such as data port.
No such Restriction.
It has a poor response time which
makes it a secondary option for
testing.
Easier and Faster to way of running
the application
Emulators can be provided
simulated triggers by using Telnet.
Easy to provide real time triggers
such as receiving a text message or
email.
Multiple AVDs (Android Virtual
Device) can be created for any
version of the android OS.
A single device can run only on
version of the Android OS.
Android
Emulator /
Android Virtual
Device
 What is an Emulator?
An emulator is a software that duplicates (or emulates) the
functions of one computer system in another computer
system. In the case of an Android Emulator , the Emulator
software closely resembles the behavior of the real Android
Device.
 What is an Android Virtual Device (AVD)?
As the name suggests it is a Virtual Device which emulates a
real Android Device that runs the Android OS. It is an
emulator configuration that lets you model an actual
device by defining hardware and software options to be
emulated by the Android Emulator.
 Follow these steps to first create an Android Virtual Device (AVD)
in the Eclipse IDE with ADT Plugin.
 Go to the Window -> Android Virtual Device Manager.
 In the Android Virtual Devices tab, Click on New..
 Or Go to the Device Definitions Tab and select a device and click
on Create AVD.
Setting up the
AVD
 Now the Create New AVD window
appears. Provide a Name for the AVD
and complete the other Configuration
options such ad the Android Version,
Memory options etc.
 Click OK. Now the AVD is created.
Deploying an
Application
In AVD
 To start the emulator Open the AVD
Manager and go to the AVDs tab.
Select an AVD and click on Start.. (The
emulator may take some time to
load)
Setting up the
Physical
Device
 In order to debug you application in a real Android
Device, the device must have ‘Developer Options’
enabled.
 For each device this option can be enabled in different
ways. For security reason, that this option may not be
enabled by mistake it might be hidden. One can Search
online in the Internet for a way to enable this option in
one’s specific device.
Deploying an
application
In the Physical
Device
 In order to run the application on your device.
 One can connect the device to the computer using
a USB cable and then Click on Run As -> Android
Application , and choose from the list of devices
available.
Deploying in
the Physical
Device
 Or one can build the Application
by selecting Project-> Build
Project , which will generate the
Android Package file (.apk file)
which will be available in the bin
folder of the project, which can
be transferred to your phone by
some means (say email) and
then installed in the Device.
 Ensure Project -> Build
Automatically is Selected.
Deploying the
Application
 Now Click on the Project in the
Package Explorer and Select
Run-> Run As -> Android
Application
 Now select the device /AVD to
run the application on.
Thank You!