android session-1-sajib

31
Android Training Session - 1 Presented By: A.T.M. Hassan Uzzaman

Upload: hussain-behestee

Post on 18-Nov-2014

94 views

Category:

Education


0 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Android session-1-sajib

Android Training

Session - 1

Presented By: A.T.M. Hassan Uzzaman

Page 2: Android session-1-sajib

Agendas

• Introduction to Android• Application Structure• Layouts & Drawable Resources• Activities and Activity lifecycle• First sample Application• Launching emulator

Page 3: Android session-1-sajib

Introduction A Linux based Operating System designed primarily for

touch screen mobile devices Initially developed by Android Inc and later purchased by Google in 2005 The first Android powered device was sold in Oct 2008 Android is Open Source and Google releases code under

Apache2 license Google Play Store

Page 4: Android session-1-sajib

Brief History – Android

2009

SDK 1.5 (Cupcake) New soft keyboard with “autocomplete” feature

SDK 1.6 (Donut) Support Wide VGA

SDK 2.0/2.0.1/2.1 (Eclair) Revamped UI, browser

2010

SDK 2.2 (Froyo) Flash support, tethering

SDK 2.3 (Gingerbread) UI update, system-wide copy-paste

Page 5: Android session-1-sajib

5

2011– SDK 3.0/3.1/3.2 (Honeycomb) for tablets onlyNew UI for tablets, support multi-core processors– SDK 4.0/4.0.1/4.0.2/4.0.3 (Ice Cream Sandwich)Changes to the UI, Voice input, NFC

2012 SDK 4.1/4.1.1/4.2(Jelly Bean) Performance optimization, refined UI

HoneycombAndroid 3.0-3.2

Ice cream SandwichAndroid 4.0+

Jelly Bean 4.1+

Page 6: Android session-1-sajib

6

API Level

Platform Version API Level Version Name

Android 4.2 17 Jelly bean

Android 4.1, 4.1.1 16 Jelly bean

Android 4.0.3, 4.0.4 15 Ice cream sandwich

Android 4.0, 4.0.1, 4.0.2 14 Ice cream sandwich

Android 3.2 13 Honey Comb

Android 3.1.x 12 Honey Comb

Android 3.0.x 11 Honey Comb

Android 2.3.4Android 2.3.3

10 Gingerbread

Page 7: Android session-1-sajib

7

API Level

Platform Version API Level Version Name

Android 2.3.2Android 2.3.1Android 2.3

9 Gingerbread

Android 2.2.x 8 Froyo

Android 2.1.x 7 Eclair

Android 2.0.1 6 Eclair

Android 2.0 5 Eclair

Android 1.6 4 Donut

Android 1.5 3 Cupcake

Page 8: Android session-1-sajib

Levels

Page 9: Android session-1-sajib

Activity BackStack

• Main activity calls activity2

Activity 2Push Operation(Last in)

Activity 2 is visible on screenMain activity goes in background

backstack

main

Page 10: Android session-1-sajib

Activity BackStack

• From activity2, user presses back button

Activity 2

Main activity is visible on screen and activity 2 is destroyed

backstack

main

Pop operation (First Out)

Page 11: Android session-1-sajib

Java Source Code

Java Byte Code

JVM

Java Byte Code

Dalvik Byte Code

Java Compiler

DexCompiler

Dalvik Executable

DVM

Dalvik Virtual Machine

Vs Java Virtual

Machine

Page 12: Android session-1-sajib

Differences between DVM and JVM

Machine

Property

DVM JVM

Architecture base

Register Stack

No of operations

fewer more

File format .dex .class

Page 13: Android session-1-sajib

JVM - Stack Based

POP 20 POP 7 ADD 20, 7, result PUSH result

Page 14: Android session-1-sajib

DVM - Register Based

Add R3,R1,R2

Page 15: Android session-1-sajib

15

Android Java Consists of

Android Java =

Java SE - AWT/Swing+

Android API

Page 16: Android session-1-sajib

APK file format: Application package file Zip package format based on JAR file format Apk holds

Code(.dex file) Resources Assets Certificates Manifest file

Once .apk is installed on a device: Own security sandbox A unique Linux UserID Own Virtual Machine Own Linux process

Application Fundamentals

Page 17: Android session-1-sajib

Android Application Components

• Activities: An Activity is an application component that provides a screen with which users can interact in order to do something.

• Services: A Service is an application component that can perform long-running operations in the background and does not provide a user interface.

• Content Providers: A content provider manages a shared set of application data.

• Broadcast Receivers: A broadcast receiver is a component that responds to system-wide broadcast announcements.

Page 18: Android session-1-sajib

Activity Lifecycle

Page 19: Android session-1-sajib

Configuring Android Development

Environment

Page 20: Android session-1-sajib

Requirements

JDK 6 (Java Development Kit ) and above– (JRE alone is not sufficient)– http://www.oracle.com/technetwork/java/javase/downloads/index.html

Eclipse IDE– Eclipse + ADT plugin– Android SDK Tools– Android Platform-tools– The latest Android platform– The latest Android system image for the emulator

• http://developer.android.com/sdk/index.html

Other development environments• Apache Ant 1.8 or later ( http://ant.apache.org/ )• Not compatible with Gnu Compiler for Java (gcj)

Note: Some Linux distributions may Include JDK 1.4 or Gnu Compiler for Java, both of which are not supported for Android development.

Page 21: Android session-1-sajib

Adding Platforms

and Packages

Figure . The Android SDK Manager shows the SDK packages that are available, already installed, or for which an update is available.

Page 22: Android session-1-sajib

Sample Application

Page 23: Android session-1-sajib

Understanding Android Project Structure

• AndroidManifest.xml– The manifest file describes the fundamental characteristics of the app and

defines each of its components.

• src/– Directory for your app's main source files. By default, it includes an Activity

class that runs when your app is launched using the app icon.

• res/– Contains several sub-directories for app resources. Here are just a few:

– drawable-hdpi/• Directory for drawable objects (such as bitmaps) that are designed for high-

density (hdpi) screens. Other drawable directories contain assets designed for other screen densities.

– layout/• Directory for files that define your app's user interface.

– values/• Directory for other various XML files that contain a collection of resources, such as string and color definitions.

Page 24: Android session-1-sajib

AndroidManifest.xml file

• Every application must have an AndroidManifest.xml file.

• The manifest presents essential information about the application to the Android system.

• 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.– It determines which processes will host application components.– It also declares the permissions that others are required to

have, in order to interact with the components of the application

– It declares the minimum level of the Android API, that the application requires.

Page 25: Android session-1-sajib

The file R.java is an auto-generated file, that is added to your application, by the Android plug-in.

This file contains pointers into the drawable, layout, and values directories.

You should never modify this file directly. You will be only referencing R.java in most of your applications.

R.Java

Page 26: Android session-1-sajib

package testPackage.HelloWorldText;

public final class R {public static final class attr {}

public static final class drawable{public static final int icon=0x7f020000;

}public static final class layout {

public static final int main=0x7f030000;}public static final class string {

public static final int app_name=0x7f040000;}

}

R.Java: Content

Page 27: Android session-1-sajib

Resources

Almost all Android applications will have some sort of resources in them; at a minimum they often have the user interface layouts in the form of XML files.

Page 28: Android session-1-sajib

• Android offers one more directory where you can keep files which also will be included is package. This directory called /assets.

•The difference between /res and /assets is that, Android does not generate IDs of assets content.

•You need to specify relative path and name, for files inside /assets.

InputStream is = getAssets().open("text.txt");

Code to Access Assets :

Page 29: Android session-1-sajib

References

www.developer.android.com

www.developer.android.com/sdk/index.html

Page 30: Android session-1-sajib

Questions ?

Page 31: Android session-1-sajib

Thank You.