first steps in android development with eclipse and xamarin
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.TRANSCRIPT
© 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
(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
Android Development Environment
Native Android
• Eclipse/Android Studio
• Android plugin for Eclipse (ADT)
• Android SDK
Xamarin (C#)
• Visual Studio• Xamarin.Android
extension• Android SDK
Demo
Hello World
Project Structure
srcgenres
layoutvalues
assetsAndroid X.X.XLibrariesAndroidManifest.xml
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
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
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
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
Demo
Connecting UI to Code
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
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
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);
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"/>
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.
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
Demo
Multiple Activities and ListView
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
Demo
Xamarin.Android
Summary
Android development environmentResources, layouts, viewsIt’s just another{language, IDE, UI framework}The rest is just details: data, networking, preferences, styling, …
QuestionsSasha Goldshtein @goldshtnCTO, SELA Group blog.sashag.net