android application development workshop day1

35
Android Application Development Workshop Day 1 Eng.Borhan Otour [email protected]

Upload: borhan-otour

Post on 19-May-2015

126 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: Android application development workshop   day1

Android Application Development Workshop

Day 1 Eng.Borhan Otour

[email protected]

Page 2: Android application development workshop   day1

Hello World , this is Android

Page 3: Android application development workshop   day1

Agenda

What we will cover today •The Android System and the Android SDK. •The eXtensible Markup language (XML). •Building and running our first Application. (project structure - AVDs) •The Project structure. •The First touch(Basic User-App Interaction) • Basic Interconnection. •Advanced Interconnection.

Page 4: Android application development workshop   day1

The Android System Architecture

Page 5: Android application development workshop   day1

The Android Market and Activations

By 2013 , there were

Android Device Activated. SO THERE IS A LOT OF PEOPLE WHO NEEDS APPS FROM YOU.

Page 6: Android application development workshop   day1

The eXtensible Markup Language (XML)

Sample: collage.xml

Page 7: Android application development workshop   day1

The XML - overview

<school…………… > - - - - - - - </school>

• Every starting tag has an end tag

• The Tag may have a child tags

<hospital> <doctor> <patient ----> --- </patient> <patient ----> --- </patient> </doctor> </hospital>

• The Tag may contain attribute

<student name=“Borhan” age=“23” ></student>

Page 8: Android application development workshop   day1

Android Application Development

1. The Installation of the development environment 2. The main application component – The Activity. 3. The View System.

Page 9: Android application development workshop   day1

The Installation

•What do you need to prepare the development environment? 1. The Android SDK 2. An editor to code your project or The Integrated

Development Environment (Eclipse IDE) 3. Connect the IDE and the SDK to begin developing for the

Android market (Android developer tool ADT)

• ( SDK + Eclipse )* ADT = My Android Development Environment

• Remember: SDK = Android development tools + Android application framework

Page 10: Android application development workshop   day1

Android Application development - Activities

The activity: the most important Android application component. It’s a java class that represent a Screen. Each application must contain one screen .

This is an Activity

Note: The activity is not a layout

Page 11: Android application development workshop   day1

Android Application development (create a simple layout) .cont

The view:

The view is the fundamental component you see in the “screen” that is used to build layouts.

The views can be containers or a widgets.

Page 12: Android application development workshop   day1

Android Application development (create a simple layout) .cont

•The layout is composed of a hierarchy of views

Page 13: Android application development workshop   day1

Building the first application “Hello World, Android”

1. Setup the Android projects workspace. 2. Create a new Android application project. 3.Launch the Android Application Project. 4.What is the project structure?

Page 14: Android application development workshop   day1

Create a new Android app project

1. Together let’s setup the workspace

2. Project creation step 1

Page 15: Android application development workshop   day1

Create a new Android app project

3. Project creation step 2

Page 16: Android application development workshop   day1

Create a new Android app project

4. Project creation step 3

Page 17: Android application development workshop   day1

Create a new Android app project

5. Project creation step 4

Page 18: Android application development workshop   day1

Create a new Android app project

6. Project creation step 5

Page 19: Android application development workshop   day1

Create a new Android app project (The Android virtual device AVD) •The Android Virtual Device (The Emulator)

Page 20: Android application development workshop   day1

The project structure - res

The static content of any Android application is called a resource. 1. images. 2. Textual content. 3. Layouts. 4. Etc …

The main idea to reach a resource is that , each resource item must have an ID. To reach to a resource ID us in XML: @resourceType/resourceID Ex: @string/app_name (in the AndroidManifest.xml)

Page 21: Android application development workshop   day1

The project structure – AndroidManifest.xml

Page 22: Android application development workshop   day1

The project structure – AndroidManifest.xml

To Set the layout content of an Activity use the: setContentView(int layoutResouceID);

Page 23: Android application development workshop   day1

Basic call Back “Android Toast”

1. Assign Id to view to get them in code. 2. Get Views in code to manipulate them. 3.Build a basic call back mechanism.

Page 24: Android application development workshop   day1

Basic callbacks : get Views In Code

The Goal: We Assign an ID to a view element like Buttons, TextView so we can reach them in code. The Way: we set an id to the view element like (TextView , Button) Using android:id=“@+id/idName” In the Activity we call the view: Using the Activity function: findViewById(int viewId) viewId = R.layout.some_layout_resource_name

Page 25: Android application development workshop   day1

Basic callbacks : (The R class)

XML resource

Java Code R.java

public final class R { public static final class string{ /** String array of all countries in the world public static final int app_name=0x7f060001; public static final int hello=0x7f060000; } ----- }

Page 26: Android application development workshop   day1

The activity_main.xml file that represents the layout of the MainActivity.java

Page 27: Android application development workshop   day1

Basic Interconnection “Two Layout Application”

1. Adding a new Activity to the project.

Page 28: Android application development workshop   day1

Creare a new Activity

Page 29: Android application development workshop   day1

Crearte a new Activity

Page 30: Android application development workshop   day1

Crearte a new Activity

Page 31: Android application development workshop   day1

Start the new Activity

The Intent Object: Intent intent = new Intent(); Put Some content in the message: intent.putExtras(String key,Object vlaue); Start The new Activity: startActivity(intent); Receive the intent object: getIntent();

Page 32: Android application development workshop   day1

Advanced Interconnection “Get Application Application”

Page 33: Android application development workshop   day1

Interconnection between activities (The Intent system)

Activity 2 Activity 1

• When you want to launch a new Activity from the current Activity you need to use Intents. • The Intent represents the Application Intention to do something, which is (launching a new “Screen”) . • You specifies the current Activity and the name of the Destination Activity in the construction of intent object. Intent intent = new Intent(this , destinationActivityName.class) • You can put extra content in the message that you send to launch a new Activity.

Intent.putExtras( String key , value);

Page 34: Android application development workshop   day1

Interconnection between activities (The Intent system) .cont

• To launch the new Activity from the current activity use the Activity method: startActivity(Intent intent) • To get the Intent object that caused the activity to be launched: In the destination Activity , use the activity method: getIntent() • To extract the extra data from the intent based of the type of data ( like String data for instance ) : intent.getStringExtras(String key)

Page 35: Android application development workshop   day1

References

•http://developer.android.com/index.html •The API documentation http://developer.android.com/reference/packages.html • Building the first application http://developer.android.com/training/basics/firstapp/index.html