android session 1

23
Android Application Development Session-1 From Beginner to Advanced By : Ahesanali Suthar email: [email protected]

Upload: ahesanali-momin

Post on 28-Jan-2015

111 views

Category:

Technology


2 download

DESCRIPTION

Android application development presentation-1

TRANSCRIPT

Page 1: Android session 1

Android Application Development Session-1From Beginner to Advanced

By : Ahesanali Sutharemail: [email protected]

Page 2: Android session 1

Topics to be Covered1. Introduction of Android.

2. Android SDK.

3. Setting Up Development Environment (Windows,Linux).

4. Creating Project in Eclipse.

5. Tutorial-1: Hello World

6. Android Project Directory Structure.

Page 3: Android session 1

1. Introduction of Android● Android is a Linux-based operating system designed primarily for

touchscreen mobile devices such as smartphones and tablet computers, developed by Google in conjunction with the Open Handset Alliance.

● Initially developed by Android Inc, whom Google financially backed and later purchased in 2005.

● Android has a large community of developers writing applications ("apps") that extend the functionality of devices, written primarily in a customized version of Java.They are available for download through Google Play or third-party sites.

● The first Android-powered phone was sold in October 2008, and by the end of 2010 Android had become the world's leading smartphone platform, overtaking Symbian which held its record for years

Page 4: Android session 1

2. Android SDK● The Android SDK (SDK refers to Software Development KIT)provides you

the API libraries and developer tools necessary to build, test, and debug apps for Android.

● Like in windows we have .NET Framework as a SDK for developing the Softwares for windows platform.Similarly java provide JDK(Java Dev. Kit).But java provide kit for Linux as well as for windows.

● To Download SDK: http://developer.android.com/sdk/index.html

● To know more about Android SDK: http://developer.android.com/sdk/exploring.html

Page 5: Android session 1

3. Dev EnvironmentSystem Requirements.(OS) (http://developer.android.com/sdk/index.html)

● Windows XP (32-bit), Vista (32- or 64-bit), or Windows 7 (32- or 64-bit)● Mac OS X 10.5.8 or later (x86 only)● Linux (tested on Ubuntu Linux, Lucid Lynx)

GNU C Library (glibc) 2.7 or later is required.On Ubuntu Linux, version 8.04 or later is required.64-bit distributions must be capable of running 32-bit applications.

Eclipse IDE

● Eclipse 3.6.2 (Helios) or greate ()● Android SDK● JDK 6 (JRE alone is not sufficient)● Android Development Tools plugin (ADT)

Page 6: Android session 1

3. Dev Environment (Cont.)● After Downloading Android SDK,We have to download platform packages.

Page 7: Android session 1

3. Dev Environment (Cont.)● Once we are done with downloading platform packages either we are

developing on Windows or Linux or Mac we need to install ADT (Android Development Toolkit) in Eclipse IDE.

To Install ADT into the Eclipse IDE follow below steps.1. Open Eclipse IDE.2. Click on Help->Install New Software from the menu bar.3. Then install window is open then Click on Add Button

Page 8: Android session 1

3. Dev Environment (Cont.)● Now when you click on Add button,you will found below window.

Insert the Name as ADT(any name can be given) and Location of ADT zip file.Location can be given by clicking on Archive button and then press Ok.Complete the procedure by clicking Next..Next...and Finish.

Page 9: Android session 1

3. Dev Environment (Cont.)Setting up SDK path into Eclipse IDE● Open Preferences window by clicking Window -> Preferences.

● If we have properly installed ADT in Eclipse we have Android option in Preferences window.

● As you can see on above image by Clicking on Android in preferences window we have option available for SDK path.

● So by clicking Browse button please select android-sdk-window folder from your computer.so SDK location field have complete path of Android SDK.So finally you have a setup ready for Android Development.

Page 10: Android session 1

4.Creating Project in Eclipse● Open Eclipse IDE.● Click on File->New->Android Project

from file menu.

● Application Name is the app name that appears to users. For this project, use "My First App."

● Project Name is the name of your project directory and the name visible in Eclipse.

● Package Name is the package namespace for your app.

● Minimum Required SDK is the lowest version of Android that your app supports, indicated using the API level.

● Target SDK indicates the highest version of Android (also using the API level) with which you have tested with your application.

● Compile With is the platform version against which you will compile your app.

● Click on Next button.

Page 11: Android session 1

4.Creating Project in Eclipse● The next screen can help you create a launcher icon for your app.Click

Next.● Now you can select an activity template from which to begin building your

app. For this project, select BlankActivity and click Next● Finally click on the Finish.

Page 12: Android session 1

5.Tutorial-1: Hello World● After creating project in eclipse ,run the project by right click on the project

name and Runs As -> Android Application.

● If simulator is created previously project will run in that other wise it eclipse will ask for create new simulator.

Page 13: Android session 1

6.Android Project Directory Structure.● Now we are learning how this hello world is printed

on the screen.

● Following Image shows android project directory structure.

● src: This is the directory where all java files for the project will reside. In java there is a concept of package so here files are maintained in packages.Like in our case there is one package called com.maktabah which we have entered at the time of project creation.

● gen: In this folder the files which are generated by android-sdk.We are not changing any of the files here,Because this is the internal reference to sdk.

Page 14: Android session 1

6.Android Project Directory Structure.● assets: Here resource type information will goes.Like

fonts file,web-pages(when we are developing android app in HTML5)

● bin: When are compiling the project all class files are generated here by java compiler.

● res: This is important folder we are discussing each inner directory in detail.

● drawable-hdpi,drawable-ldpi,drawable-mdpi,drawable-xhdpi: These are the directories where we are putting images that are used in projects.○ But we have question like why these many

directories(4 directories).So the answer is these are the directory dedicated for different screen density(in Desktop computer terminology we call it resolution of the Monitor).

Page 15: Android session 1

6.Android Project Directory Structure.

○ How android app decide which image to talk when it is referenced from code we will see it when we see implementation of the sample tutorial.

● To read more about for these directories please follow the link:

http://developer.android.com/guide/practices/screens_support.html

● Consider following image for example.

Page 16: Android session 1

6.Android Project Directory Structure.

i. xlarge screens are at least 960dp x 720dpii. large screens are at least 640dp x 480dpiii. normal screens are at least 470dp x 320dpiv. small screens are at least 426dp x 320dp

● layout: This is the directory where we are putting all design files in xml format.As we can see from right side image when we create new project default main.xml file is there.

● These layout xmls files are responsible for the user-interface and look and feel of the app.

● Like in windows application when we are working in visual studio IDE we have two files one for design and one for code.Whenever we place button in design and double click on it and button_click function in different file and button User interface is in design file

Page 17: Android session 1

6.Android Project Directory Structure.● Sample Layout code:

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" >

<TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" />

</LinearLayout>

Page 18: Android session 1

6.Android Project Directory Structure.● values: It contains all xml file for values like styles xml,

string constants and other.

● As we can see im right side image the when we create a new android project it only contains string.xml which contains strings values in xml format for whole project.

● Strings for lable,error message and titles etc are stored in string.xml files.We can also write strings at lable in layout.xml, but it is good practice to declare strings in string.xml for managing resource in project and reusability

Page 19: Android session 1

6.Android Project Directory Structure.● Example of basic string.xml:

<?xml version="1.0" encoding="utf-8"?><resources>

<string name="hello">Hello World, HelloWorldActivity!</string> <string name="app_name">HelloWorld</string>

</resources>

Page 20: Android session 1

6.Android Project Directory Structure.AndroidManifest.xml:

● This is the file where we declaring application components like Activities,Services,Broadcast-Receivers.

● Allowing permissions to application

● We can also call it is a configuration file for the app.

Page 21: Android session 1

6.Android Project Directory Structure.Sample of Manifest for HelloWord App:<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.maktabah" android:versionCode="1" android:versionName="1.0" >

<uses-sdk android:minSdkVersion="8" />

<application android:icon="@drawable/ic_launcher" android:label="@string/app_name" > <activity android:name=".HelloWorldActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application></manifest>

Page 22: Android session 1

Questions ?

Page 23: Android session 1