android programming module 1 – getting started

22
ANDROID PROGRAMMING MODULE 1 – GETTING STARTED DEPARTMENT OF COMPUTER SCIENCE IOWA STATE UNIVERSITY

Upload: leal

Post on 16-Feb-2016

71 views

Category:

Documents


0 download

DESCRIPTION

ANDROID PROGRAMMING MODULE 1 – GETTING STARTED. DEPARTMENT OF COMPUTER SCIENCE IOWA STATE UNIVERSITY. Concepts Android OS Android Programming Setting up the development environment. ADT Eclipse IDE SKD Manager Creating an Android Project More Concepts Activity - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: ANDROID PROGRAMMING MODULE  1 –  GETTING STARTED

ANDROID PROGRAMMINGMODULE 1 – GETTING STARTEDDEPARTMENT OF COMPUTER SCIENCEIOWA STATE UNIVERSITY

Page 2: ANDROID PROGRAMMING MODULE  1 –  GETTING STARTED

ROADMAP

Concepts Android OS Android Programming

Setting up the development environment. ADT Eclipse IDE SKD Manager

Creating an Android Project More Concepts

Activity Basic Structure of an Android Project Deployment

Page 3: ANDROID PROGRAMMING MODULE  1 –  GETTING STARTED

Concepts

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.

Android Programming Applications are usually developed in the Java

programming language using the Android Software Development Kit, but other development tools are also available.

Page 4: ANDROID PROGRAMMING MODULE  1 –  GETTING STARTED

Setting up the Development EnvironmentDownload

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.

Page 5: ANDROID PROGRAMMING MODULE  1 –  GETTING STARTED

Setting up the Development EnvironmentAndroid SDK and SDK Manager

After Downloading the Package and extracting it. You will see that there are three items:

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.

Page 6: ANDROID PROGRAMMING MODULE  1 –  GETTING STARTED

Setting up the Development EnvironmentEclipse IDE with ADT Plugin

Open the Eclipse folder which contains the Eclipse IDE files and click on the Application file named Eclipse.

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.

Page 7: ANDROID PROGRAMMING MODULE  1 –  GETTING STARTED

Creating an Android Project

Now the Workbench Opens and one can see the Java Perspective set by default in the top right corner of the window.

To Create a new Android Project follow these steps. Select File -> New -> Android Application Project.

Java Perspective

Page 8: ANDROID PROGRAMMING MODULE  1 –  GETTING STARTED

Creating an Android ProjectApplication and Package Names

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.

Page 9: ANDROID PROGRAMMING MODULE  1 –  GETTING STARTED

Creating an Android ProjectConfigure 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.

Page 10: ANDROID PROGRAMMING MODULE  1 –  GETTING STARTED

Creating an Android ProjectIcon and Activity

Click Next in the Configure Attribute for the icon art window

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.

Page 11: ANDROID PROGRAMMING MODULE  1 –  GETTING STARTED

Creating an Android Project

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.

Contents of Project

Page 12: ANDROID PROGRAMMING MODULE  1 –  GETTING STARTED

Structure of the Android Project

src : Contains source files and packages. gen: Contains files generated on building the

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.

Page 13: ANDROID PROGRAMMING MODULE  1 –  GETTING STARTED

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.

Page 14: ANDROID PROGRAMMING MODULE  1 –  GETTING STARTED

Two Ways of Debugging

Android Virtual Device Physical DeviceDoes 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.

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.

Page 15: ANDROID PROGRAMMING MODULE  1 –  GETTING STARTED

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.

Page 16: ANDROID PROGRAMMING MODULE  1 –  GETTING STARTED

Setting up the AVD

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.

Page 17: ANDROID PROGRAMMING MODULE  1 –  GETTING STARTED

Deploying an ApplicationIn 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. 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)

Page 18: ANDROID PROGRAMMING MODULE  1 –  GETTING STARTED

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.

Page 19: ANDROID PROGRAMMING MODULE  1 –  GETTING STARTED

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.

Page 20: ANDROID PROGRAMMING MODULE  1 –  GETTING STARTED

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.

Page 21: ANDROID PROGRAMMING MODULE  1 –  GETTING STARTED

Deploying the Application

Ensure Project -> Build Automatically is Selected.

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.

Page 22: ANDROID PROGRAMMING MODULE  1 –  GETTING STARTED

Thank You!