21
© Copyright SELA software & Education Labs Ltd. | 14-18 Baruch Hirsch St Bnei Brak, 51202 Israel | www.selagroup.com Sasha Goldshtein @goldshtn CTO, SELA Group blog.sashag.net First Steps in Android Development

First Steps in Android Development with Eclipse and Xamarin

Embed Size (px)

DESCRIPTION

Presentation from the Toronto TechHub user group on Android development. Introducing basic development concepts with Eclipse and then switching to Xamarin.Android and Visual Studio.

Citation preview

Page 1: First Steps in Android Development with Eclipse and Xamarin

© Copyright SELA software & Education Labs Ltd. | 14-18 Baruch Hirsch St Bnei Brak, 51202 Israel | www.selagroup.com

Sasha Goldshtein @goldshtnCTO, SELA Group blog.sashag.netFirst Steps in Android Development

Page 2: First Steps in Android Development with Eclipse and Xamarin

(Relevant) Android Versions

Froyo•Android 2.2

Gingerbread•Android 2.3.x

Honeycomb•Android 3.x

Ice Cream Sandwich•Android 4.0

Jelly Bean•Android 4.1-4.3

KitKat•Android 4.4

Page 3: First Steps in Android Development with Eclipse and Xamarin

Android Development Environment

Native Android

• Eclipse/Android Studio

• Android plugin for Eclipse (ADT)

• Android SDK

Xamarin (C#)

• Visual Studio• Xamarin.Android

extension• Android SDK

Page 4: First Steps in Android Development with Eclipse and Xamarin

Demo

Hello World

Page 5: First Steps in Android Development with Eclipse and Xamarin

Project Structure

srcgenres

layoutvalues

assetsAndroid X.X.XLibrariesAndroidManifest.xml

Page 6: First Steps in Android Development with Eclipse and Xamarin

What Makes an Android Application?

• Presentation layer• Derive from Activity

• Use Views• Similar to forms in

the desktop world

Activities

• Worker processes in application

• Invisible• Responsible for

updating data sources, activities, notifications

Services

• Shareable data store

• Preferred way to share data across applications

Content Providers

• Message-passing framework

• Broadcast messages to target activity/service

Intents

• Broadcast consumers

• Filtered by criteria• Listen to intents

that match the criteria

Broadcast Receivers

• Enables notifications without interrupting the current activity

• Device notification area

Notifications

Page 7: First Steps in Android Development with Eclipse and Xamarin

Resources

Resources are non-code application partsAndroid resources include images, strings, simple values, animations, themes, etc.

Best to keep separated/external from codeExternal resources are easier to maintain, upgrade, and manage (…and localize!)

Created under the res folder

Page 8: First Steps in Android Development with Eclipse and Xamarin

Layout Resources

Layouts specify the UIDecouple presentation layer from codeEnable designing UI in XML Can be referenced as any other resource from other layouts

Usually, each layout XML file = view

Page 9: First Steps in Android Development with Eclipse and Xamarin

Code and User Interface Separation

Strive to define most of the UI in XML files, and write only code in Java files

Clean code/UI separation provides flexibility and easy maintenanceMakes it easier to adjust for various types of hardware devices (similar to resource localization)

UI elements can be manipulated from code

Use findViewById to get UI element instance from code

Page 10: First Steps in Android Development with Eclipse and Xamarin

Demo

Connecting UI to Code

Page 11: First Steps in Android Development with Eclipse and Xamarin

Localization

Resources make localization easyCreate a language-specific folder structure alongside the main folder structureFolder name includes qualifiers

+ res+ values

+ strings.xml

+ values-fr+ strings.xml

+ values-fr-rCA+ strings.xml

Page 12: First Steps in Android Development with Eclipse and Xamarin

What Is an Activity?

An activity represents a screenUsing Views to provide UIExtends the Activity classTo navigate screens, start a new activity using an intent

By default, activities occupy the entire screenCan create semi-transparent/floating activities

Last-in-first-out activity stackNew activity pushes foreground activity down into stackNavigating back or finishing an activity pops from the stack the previous activity

Page 13: First Steps in Android Development with Eclipse and Xamarin

Creating Activities

Extend the Activity classThe base class presents an empty screenEncapsulates window display handling functionality

User interfaces are created using ViewsCan create UI from layout or from View-derived instances

//Using a layout resource identifier:setContentView(R.layout.main);

//Using a View-derived instance:TextView text = new TextView(this);text.setText("New text!");setContentView(text);

Page 14: First Steps in Android Development with Eclipse and Xamarin

Multiple Activities

Span a sub-activity using an IntentAll activities must be declared in the application manifest

Intent launch = new Intent(this, SecondaryActivity.class);

startActivity(launch);

<activity android:name=".SecondaryActivity"/>

Page 15: First Steps in Android Development with Eclipse and Xamarin

Layouts

Most commonly used layouts

Multiple layouts can be mixed together

Layout DescriptionFrameLayout Pins child views to the top left corner. Adding multiple

children stacks each new child on top of the previous, with each new view obscuring the last.

LinearLayout Adds each child view in a straight line, either vertically or horizontally.

RelativeLayout Enables defining the positions of each of the child views relative to each other and the screen boundaries.

TableLayout Lay out views using a grid of rows and columns.

Page 16: First Steps in Android Development with Eclipse and Xamarin

Selectors and Lists

ListView provides a convenient UI for value selection from a long list

Presents multiple items on screen

Spinner provides UI for value selection

Presents only a single value at a timeDrop-down overlay of selectable items

Page 17: First Steps in Android Development with Eclipse and Xamarin

Demo

Multiple Activities and ListView

Page 18: First Steps in Android Development with Eclipse and Xamarin

Xamarin: C# on 3 Billion Devices

Xamarin provides a .NET runtime for iOS and Android development in C#Proprietary IDE: Xamarin StudioFull Visual Studio integration

Page 19: First Steps in Android Development with Eclipse and Xamarin

Demo

Xamarin.Android

Page 20: First Steps in Android Development with Eclipse and Xamarin

Summary

Android development environmentResources, layouts, viewsIt’s just another{language, IDE, UI framework}The rest is just details: data, networking, preferences, styling, …

Page 21: First Steps in Android Development with Eclipse and Xamarin

QuestionsSasha Goldshtein @goldshtnCTO, SELA Group blog.sashag.net