SlideShare uma empresa Scribd logo
1 de 84
Building your first Android
app using Xamarin
Gill Cleeren - @gillcleeren
Hi, I’m Gill!
Gill Cleeren
MVP and Regional Director
.NET Practice Manager @ Ordina
Trainer & speaker
@gillcleeren
gill@snowball.be
I’m a Pluralsight author!
• Courses on Windows 8, social and HTML5
• http://gicl.me/mypscourses
Agenda
• Overview of Xamarin and Xamarin.Android
• Xamarin.Android fundamentals
• Creating a detail screen
• Lists and navigation
• Navigating from master to detail
• (Optional) Intro to using Fragments
• Optimizing the application
• Preparing for store deployment
Targets of this talk
• Understanding the fundamentals of Android app development with
Xamarin
• See how a fully working app can be built
The demo scenario
• Android Coffee Store Manager
• List of coffee
• Navigation to details page
DEMO
Looking at the finished application
Overview of Xamarin and
Xamarin.Android
Hello Xamarin
• Xamarin enables developers to reach all major mobile platforms!
• Native User Interface
• Native Performance
• Shared Code Across Platforms
• C# & .NET Framework
• Toolset on top of Visual Studio
• Enables VS to create native iOS and Android apps
• Commercial product
Write Everything in C#
iOS, Android, Windows, Windows Phone, Mac
Billions of Devices covered!
The Xamarin platform
Xamarin
Xamarin.Android Xamarin.iOS Xamarin Forms
Xamarin.Android exposes many extra device
types
Xamarin.Android
Anything you can do in Java/Android can be done in C# and
Visual Studio (or Xamarin Studio) with Xamarin!
How Xamarin works on Android
• Mono VM + Java VM execute side-by-side (supports both Dalvik and
ART)
• Mono VM JITs IL into native code and executes most of your code
• Can utilize native libraries directly as well as .NET BCL
A word on code-sharing
• Xamarin brings development time through the use of code-sharing
• Possible (currently!) using
• Shared projects:
• allows organizing the shared code
• #if directives for platform specific code
• PCL
• “include” the platforms we want to support
• Abstract to interfaces where platforms have specific implementations
Target architecture for a Xamarin app
Preparing for
Android development
What you need for Xamarin.Android
development
• Xamarin license (Xamarin.Android)
• PC or Mac
• Visual Studio or Xamarin Studio
• Android SDK and Emulators (installed via Xamarin setup)
• Emulator
• Device (not really required but...)
Installing Xamarin.Android
A word on emulators
• Setup will install some basic emulators for you
• They’re great… for drinking a lot of coffee
Alternatives for the default emulators
• Possible options
• Genymotion
-Requires VirtualBox under the hood
• HAXM drivers
• Android Player from Xamarin
• Microsoft Android emulator
• Hyper-V
Developing with a device
• 3 steps
• Enable Debugging on the Device
• Install USB Drivers (Windows only)
• Connect the Device to the Computer
Enable device debugging
• Tap the Build number 7 times to reveal
developer options
DEMO
A quick look at the development setup
Xamarin.Android
fundamentals
File  New Project
File  New Project
Fundamental #1: Activities
• Apps are collections of activities
• A view == an activity (for now )
• Apps don’t have an “entry point”
• No single code line which is called by the OS
• Apps start when Android creates one of the classes of the app
• App then gets loaded into memory
Fundamental #1: Activities
• When opening an application, the OS creates the first Activity
• Activity is a specific class
• Defines UI and behaviour for a single task
• Corresponds to a single app screen
• App gets loaded in memory
OS
User launches app
Activity
Android loads app
In memory
Fundamental #1: Activities
• One activity needs to be the “entry point” for the app:
MainLauncher=True
Activity lifecycle
Activity lifecycle
• We can of course override these methods
• OnCreate:
• Create views, initialize variables, and do other prep work before the user sees the
Activity
• This method is called only once when the Activity is loaded into memory
• OnResume
• Perform any tasks that need to happen every time the Activity returns to the device
screen
• OnPause
• Perform any tasks that need to happen every time the Activity leaves the device screen
Activity lifecycle in effect
Fundamental #2: Views
• The layout of the app is contained in *.axml files
• AXML: Android designer file / Android XML
• First view of the app is named Main.axml
• Can be any name really
• AXML files live in the Resources/layout folder
The designer for Xamarin.Android views
The designer for Xamarin.Android views
View code
Connecting and accessing controls from code
• Linking a view with an activity is done using SetContentView
Connecting and accessing controls from code
• We can name controls using the ID property
• The Android designer maps the control to the Resource class and assigns it a
resource ID
• The code representation of a control is
linked to the visual representation
of the control in the
designer via the Id
property
Connecting and accessing controls from code
• Once we have created the controls, we can access them from code
• Field name is used for lookup
Fundamental #3: Application manifest
• An Android app contains a manifest file
• Contains a list of all resources, properties… that make up the application
• Also contains name, list of permissions… that the application has received
Images
Icons
*.axml
Others
Android Manifest file
DEMO
Creating our first Android application together!
Navigation and lists
Fundamental #4: ListViews and adapters
• Used very commonly in Android
• Common way to present lists of rows
• Each row is represented using a standard style or customized
• Consists out of
• ListView: visual part
• Adapter: feeds data to ListView
Fundamental #4: ListViews and adapters
Important classes
• ListView
• ListActivity
• BaseAdapter
• ArrayAdapter & ArrayAdapter<T>
ListActivity and the built-in ArrayAdapter<T>
[Activity(Label = "Coffees", MainLauncher = true, Icon = "@drawable/icon")]
public class CoffeeScreenActivity: ListActivity
{
string[] coffees;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
coffees= new string[] { "Coffee 1","Coffee 2", "Coffee 3"};
ListAdapter = new ArrayAdapter<String>(
this,
Android.Resource.Layout.SimpleListItem1,
coffees);
}
}
Implementing your own adapter
• In most cases, the ArrayAdapter won’t be enough
• We’ll need to create our own adapter
• Inherits from BaseAdapter
• Things we need to implement
• Count:
• To tell the control how many rows are in the data
• GetView:
• To return a View for each row, populated with data. This method has a parameter for the
ListView to pass in an existing, unused row for re-use
• GetItemId:
• Return a row identifier (typically the row number, although it can be any long value that you
like)
• this[int] indexer:
• To return the data associated with a particular row number
Handling row clicks
• To handle row clicks, we need to implement OnListItemClick
protected override void OnListItemClick(ListView l, View v, int position, long id)
{
var t = items[position];
//do something
}
DEMO
Adding a ListView and an adapter
Customizing the ListView with other row views
Customizing the ListView with other row views
Customizing the ListView with other row views
DEMO
Using the built-in row views
Creating your own row views
• Custom row layouts are AXML files in Resources/layout
• Are loaded by Id using a custom adapter
• View can contain any number of display classes with custom colors, fonts…
Creating your own
row view
<?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="wrap_content"
android:padding="8dp"
android:orientation="horizontal">
<ImageView
android:id="@+id/CoffeeImageView"
android:layout_width="50dp"
android:layout_height="50dp"
android:padding="5dp" />
<LinearLayout
android:id="@+id/TextFields"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dip">
<TextView
android:id="@+id/CoffeeNameText"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/PriceText"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
Using your custom row view
public override View GetView(int position, View convertView, ViewGroup parent)
{
//custom view
var item = items[position];
if (convertView == null)
{
convertView = context.LayoutInflater.Inflate (Resource.Layout.CoffeeRowView, null);
}
convertView.FindViewById<ImageView>
(Resource.Id.CoffeeImageView).SetImageResource(
imageRepository.ImageNameToResourceInt(item.ImageId.ToString()));
convertView.FindViewById<TextView>
(Resource.Id.CoffeeNameText).Text = item.CoffeeName;
convertView.FindViewById<TextView>
(Resource.Id.PriceText).Text = item.Price.ToString();
return convertView;
}
DEMO
Adding our own custom row view
Fundamental #5: Intents
• An Intent is an abstract concept for some sort of operation that
should be performed in Android
• Navigating to another activity
• Often, launching an external application (= built-in) with the intent of doing
something
• Make a phone call
• Launch a URI
• Map an address
• An intent often consist out of
• What the intent is
• The data needed for the intent
• Phone number to call
Intent of making a phone call
• ActionCall asks Android for an Activity to make a phone call
Intent of navigating to another screen
• StartActivity can be used to start another activity
• PutExtra() is used to pass data from one activity to the other
var intent = new Intent ();
intent.SetClass (this, typeof(CoffeeDetailActivity));
intent.PutExtra ("selectedCoffeeId", t.CoffeeId);
StartActivity (intent);
Receiving information from the intent
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
SetContentView (Resource.Layout.Main);
var selectedCoffeeId = Intent.Extras.GetInt ("selectedCoffeeId", 0);
Coffee coffee = DataService.GetCoffeeById (selectedCoffeeId);
}
DEMO
Navigating from the List
to the Detail page
Adding Fragments
The need for Fragments
• Larger screen: more complex to build UIs that look good on all
screens
• Layouts which look good on a small screen may not look good on a large
tablet screen
• Android V3.0 introduced Fragments
• Fragment is a UI module
• UI gets divided into reusable parts
• Each “part” is an separate activity
• At run time, the Activities themselves will decide which Fragments to use
• Also work in older versions through Support packages
The need for Fragments
FragmentManager
• To help an Activity coordinate and manage all these Fragments,
Android introduced a new class called the FragmentManager
• Each activity has an instance of the FragmentManager
• Allows finding, adding and removing fragments
Adding a fragment to an Activity
• We can add the Fragment to the Activity in 2 ways
• Declaratively:
• Fragments can be used declaratively within .axml layout files by using the <Fragment>
tag
• Programmatically
• Fragments can also be instantiated dynamically by using the FragmentManager class’s
API
DEMO
Refactoring to Fragments
Optimizing
the application
Managing strings in strings.xml
• We can have Android store string values for us
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, Click Me!</string>
<string name="app_name">AndroidCoffeeStore</string>
<string name="coffeeNameLabel">Coffee name</string>
</resources>
<TextView
android:text="@string/coffeeNameLabel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/CoffeeNameLabel" />
Making the app multi-language
Application drawables
• We can add drawables: application icons
• Adding all resolutions makes sure the icons look good on all screens
• Filenames are the same
• Folder name identifies the resolution
Application drawables
• We can select an image in the project properties
• This now becomes the icon for the application within Android
DEMO
Adding resources
and drawables to the application
Deploying
to the store
Publishing your work
• Marketplace is most common option
• Often, more than one is used (Google Play, Amazon, GetJar…)
• Email or website is often for a more closed distribution
• Also require less work to prepare the application for distribution
• Google Play is best known store
• Allows users to discover, download, rate, and pay for applications by clicking a
single icon either on their device or on their computer
• Google Play also provides tools to assist in the analysis of sales and market
trends and to control which devices and users may download an application
Summary
• Xamarin.Android leverages your C# knowledge to build apps for
Android
• Concepts of Android mean a learning curve
Thanks!
Q&A
Building your first Android
app using Xamarin
Gill Cleeren - @gillcleeren
Your feedback is important!
Scan the QR Code and let us know via the TechDays App.
Laat ons weten wat u van de sessie vindt via de TechDays App!
Scan de QR Code.
Bent u al lid van de Microsoft Virtual Academy?! Op MVA kunt u altijd iets
nieuws leren over de laatste technologie van Microsoft. Meld u vandaag aan
op de MVA Stand. MVA biedt 7/24 gratis online training on-demand voor IT-
Professionals en Ontwikkelaars.

Mais conteúdo relacionado

Mais procurados

Hybrid Mobile App Development - Xamarin
Hybrid Mobile App Development - XamarinHybrid Mobile App Development - Xamarin
Hybrid Mobile App Development - XamarinDeepu S Nath
 
Cross platform Xamarin Apps With MVVM
Cross platform Xamarin Apps With MVVMCross platform Xamarin Apps With MVVM
Cross platform Xamarin Apps With MVVMJim Bennett
 
Deep Dive in Xamarin.Forms
Deep Dive in Xamarin.FormsDeep Dive in Xamarin.Forms
Deep Dive in Xamarin.FormsJames Montemagno
 
Introduction to Xamarin
Introduction to XamarinIntroduction to Xamarin
Introduction to XamarinBrian Anderson
 
Introduction to Xamarin for Visual Studio 2017
Introduction to Xamarin for Visual Studio 2017Introduction to Xamarin for Visual Studio 2017
Introduction to Xamarin for Visual Studio 2017Xamarin
 
Intro to Xamarin.Forms for Visual Studio 2017
Intro to Xamarin.Forms for Visual Studio 2017Intro to Xamarin.Forms for Visual Studio 2017
Intro to Xamarin.Forms for Visual Studio 2017Xamarin
 
Xamarin Platform
Xamarin PlatformXamarin Platform
Xamarin PlatformLiddle Fang
 
Building Your First Xamarin.Forms App
Building Your First Xamarin.Forms AppBuilding Your First Xamarin.Forms App
Building Your First Xamarin.Forms AppXamarin
 
Intro to Xamarin for Visual Studio: Native iOS, Android, and Windows Apps in C#
Intro to Xamarin for Visual Studio: Native iOS, Android, and Windows Apps in C#Intro to Xamarin for Visual Studio: Native iOS, Android, and Windows Apps in C#
Intro to Xamarin for Visual Studio: Native iOS, Android, and Windows Apps in C#Xamarin
 
Introduction to Xamarin
Introduction to XamarinIntroduction to Xamarin
Introduction to XamarinGuy Barrette
 
Native App Development for iOS, Android, and Windows with Visual Studio
Native App Development for iOS, Android, and Windows with Visual StudioNative App Development for iOS, Android, and Windows with Visual Studio
Native App Development for iOS, Android, and Windows with Visual StudioXamarin
 
Cross platform mobile web apps
Cross platform mobile web appsCross platform mobile web apps
Cross platform mobile web appsJames Pearce
 
Introduction to Xamarin.Forms
Introduction to Xamarin.FormsIntroduction to Xamarin.Forms
Introduction to Xamarin.FormsJames Montemagno
 
Get the Most out of Android 8 Oreo with Visual Studio Tools for Xamarin
Get the Most out of Android 8 Oreo with Visual Studio Tools for XamarinGet the Most out of Android 8 Oreo with Visual Studio Tools for Xamarin
Get the Most out of Android 8 Oreo with Visual Studio Tools for XamarinXamarin
 
.NET North UG - What’s new & next for Xamarin developers
.NET North UG - What’s new & next for Xamarin developers.NET North UG - What’s new & next for Xamarin developers
.NET North UG - What’s new & next for Xamarin developersJames Montemagno
 

Mais procurados (20)

Introduction to xamarin
Introduction to xamarinIntroduction to xamarin
Introduction to xamarin
 
Hybrid Mobile App Development - Xamarin
Hybrid Mobile App Development - XamarinHybrid Mobile App Development - Xamarin
Hybrid Mobile App Development - Xamarin
 
Xamarin.Forms
Xamarin.FormsXamarin.Forms
Xamarin.Forms
 
Cross platform Xamarin Apps With MVVM
Cross platform Xamarin Apps With MVVMCross platform Xamarin Apps With MVVM
Cross platform Xamarin Apps With MVVM
 
Deep Dive in Xamarin.Forms
Deep Dive in Xamarin.FormsDeep Dive in Xamarin.Forms
Deep Dive in Xamarin.Forms
 
Introduction to Xamarin
Introduction to XamarinIntroduction to Xamarin
Introduction to Xamarin
 
Introduction to Xamarin for Visual Studio 2017
Introduction to Xamarin for Visual Studio 2017Introduction to Xamarin for Visual Studio 2017
Introduction to Xamarin for Visual Studio 2017
 
Intro to Xamarin.Forms for Visual Studio 2017
Intro to Xamarin.Forms for Visual Studio 2017Intro to Xamarin.Forms for Visual Studio 2017
Intro to Xamarin.Forms for Visual Studio 2017
 
Xamarin Platform
Xamarin PlatformXamarin Platform
Xamarin Platform
 
Building Your First Xamarin.Forms App
Building Your First Xamarin.Forms AppBuilding Your First Xamarin.Forms App
Building Your First Xamarin.Forms App
 
Intro to Xamarin for Visual Studio: Native iOS, Android, and Windows Apps in C#
Intro to Xamarin for Visual Studio: Native iOS, Android, and Windows Apps in C#Intro to Xamarin for Visual Studio: Native iOS, Android, and Windows Apps in C#
Intro to Xamarin for Visual Studio: Native iOS, Android, and Windows Apps in C#
 
Xamarin microsoft graph
Xamarin microsoft graphXamarin microsoft graph
Xamarin microsoft graph
 
Introduction to Xamarin
Introduction to XamarinIntroduction to Xamarin
Introduction to Xamarin
 
Native App Development for iOS, Android, and Windows with Visual Studio
Native App Development for iOS, Android, and Windows with Visual StudioNative App Development for iOS, Android, and Windows with Visual Studio
Native App Development for iOS, Android, and Windows with Visual Studio
 
Cross platform mobile web apps
Cross platform mobile web appsCross platform mobile web apps
Cross platform mobile web apps
 
Introduction to Xamarin.Forms
Introduction to Xamarin.FormsIntroduction to Xamarin.Forms
Introduction to Xamarin.Forms
 
Get the Most out of Android 8 Oreo with Visual Studio Tools for Xamarin
Get the Most out of Android 8 Oreo with Visual Studio Tools for XamarinGet the Most out of Android 8 Oreo with Visual Studio Tools for Xamarin
Get the Most out of Android 8 Oreo with Visual Studio Tools for Xamarin
 
.NET North UG - What’s new & next for Xamarin developers
.NET North UG - What’s new & next for Xamarin developers.NET North UG - What’s new & next for Xamarin developers
.NET North UG - What’s new & next for Xamarin developers
 
Xamarin introduction
Xamarin introductionXamarin introduction
Xamarin introduction
 
Introduction to xamarin
Introduction to xamarinIntroduction to xamarin
Introduction to xamarin
 

Semelhante a Building your first android app using Xamarin

Building your first android app using xamarin (Gill Cleeren)
Building your first android app using xamarin (Gill Cleeren)Building your first android app using xamarin (Gill Cleeren)
Building your first android app using xamarin (Gill Cleeren)Visug
 
Native script overview
Native script overviewNative script overview
Native script overviewBaskar rao Dsn
 
Lec005 android start_program
Lec005 android start_programLec005 android start_program
Lec005 android start_programEyad Almasri
 
Android application development for TresmaxAsia
Android application development for TresmaxAsiaAndroid application development for TresmaxAsia
Android application development for TresmaxAsiaMichael Angelo Rivera
 
Native Script Overview
Native Script OverviewNative Script Overview
Native Script OverviewBaskar rao Dsn
 
Matteo Gazzurelli - Introduction to Android Development - Have a break edition
Matteo Gazzurelli - Introduction to Android Development - Have a break editionMatteo Gazzurelli - Introduction to Android Development - Have a break edition
Matteo Gazzurelli - Introduction to Android Development - Have a break editionDuckMa
 
Android Studio development model and.pptx
Android Studio development model and.pptxAndroid Studio development model and.pptx
Android Studio development model and.pptxVaibhavKhunger2
 
Android Application Development Using Java
Android Application Development Using JavaAndroid Application Development Using Java
Android Application Development Using Javaamaankhan
 
Native Script Atlanta Code Camp
Native Script Atlanta Code CampNative Script Atlanta Code Camp
Native Script Atlanta Code CampBaskar rao Dsn
 
Native script overview
Native script overviewNative script overview
Native script overviewBaskar rao Dsn
 
Androidoscon20080721 1216843094441821-9
Androidoscon20080721 1216843094441821-9Androidoscon20080721 1216843094441821-9
Androidoscon20080721 1216843094441821-9Gustavo Fuentes Zurita
 
Androidoscon20080721 1216843094441821-9
Androidoscon20080721 1216843094441821-9Androidoscon20080721 1216843094441821-9
Androidoscon20080721 1216843094441821-9Gustavo Fuentes Zurita
 
[2015/2016] Apache Cordova
[2015/2016] Apache Cordova[2015/2016] Apache Cordova
[2015/2016] Apache CordovaIvano Malavolta
 
Introduction to android sessions new
Introduction to android   sessions newIntroduction to android   sessions new
Introduction to android sessions newJoe Jacob
 
Android Workshop
Android WorkshopAndroid Workshop
Android WorkshopJunda Ong
 

Semelhante a Building your first android app using Xamarin (20)

Building your first android app using xamarin (Gill Cleeren)
Building your first android app using xamarin (Gill Cleeren)Building your first android app using xamarin (Gill Cleeren)
Building your first android app using xamarin (Gill Cleeren)
 
Android - Anroid Pproject
Android - Anroid PprojectAndroid - Anroid Pproject
Android - Anroid Pproject
 
Native script overview
Native script overviewNative script overview
Native script overview
 
Presentation1
Presentation1Presentation1
Presentation1
 
Lec005 android start_program
Lec005 android start_programLec005 android start_program
Lec005 android start_program
 
Android application development for TresmaxAsia
Android application development for TresmaxAsiaAndroid application development for TresmaxAsia
Android application development for TresmaxAsia
 
Native Script Overview
Native Script OverviewNative Script Overview
Native Script Overview
 
Matteo Gazzurelli - Introduction to Android Development - Have a break edition
Matteo Gazzurelli - Introduction to Android Development - Have a break editionMatteo Gazzurelli - Introduction to Android Development - Have a break edition
Matteo Gazzurelli - Introduction to Android Development - Have a break edition
 
Dfc 2018 NativeScript
Dfc 2018 NativeScriptDfc 2018 NativeScript
Dfc 2018 NativeScript
 
Android Studio development model and.pptx
Android Studio development model and.pptxAndroid Studio development model and.pptx
Android Studio development model and.pptx
 
Pertemuan 3 pm
Pertemuan 3   pmPertemuan 3   pm
Pertemuan 3 pm
 
Android Application Development Using Java
Android Application Development Using JavaAndroid Application Development Using Java
Android Application Development Using Java
 
Native Script Atlanta Code Camp
Native Script Atlanta Code CampNative Script Atlanta Code Camp
Native Script Atlanta Code Camp
 
Android class provider in mumbai
Android class provider in mumbaiAndroid class provider in mumbai
Android class provider in mumbai
 
Native script overview
Native script overviewNative script overview
Native script overview
 
Androidoscon20080721 1216843094441821-9
Androidoscon20080721 1216843094441821-9Androidoscon20080721 1216843094441821-9
Androidoscon20080721 1216843094441821-9
 
Androidoscon20080721 1216843094441821-9
Androidoscon20080721 1216843094441821-9Androidoscon20080721 1216843094441821-9
Androidoscon20080721 1216843094441821-9
 
[2015/2016] Apache Cordova
[2015/2016] Apache Cordova[2015/2016] Apache Cordova
[2015/2016] Apache Cordova
 
Introduction to android sessions new
Introduction to android   sessions newIntroduction to android   sessions new
Introduction to android sessions new
 
Android Workshop
Android WorkshopAndroid Workshop
Android Workshop
 

Mais de Gill Cleeren

Continuous integration and delivery with Xamarin and VSTS
Continuous integration and delivery with Xamarin and VSTSContinuous integration and delivery with Xamarin and VSTS
Continuous integration and delivery with Xamarin and VSTSGill Cleeren
 
Real world apps with Xamarin and MVVM
Real world apps with Xamarin and MVVMReal world apps with Xamarin and MVVM
Real world apps with Xamarin and MVVMGill Cleeren
 
Bootstrap: the full overview
Bootstrap: the full overviewBootstrap: the full overview
Bootstrap: the full overviewGill Cleeren
 
Top 10 HTML5 features every developer should know!
Top 10 HTML5 features every developer should know!Top 10 HTML5 features every developer should know!
Top 10 HTML5 features every developer should know!Gill Cleeren
 
Building a community - BuildStuff Lithuania 2014
Building a community - BuildStuff Lithuania 2014Building a community - BuildStuff Lithuania 2014
Building a community - BuildStuff Lithuania 2014Gill Cleeren
 
C# everywhere: Xamarin and cross platform development
C# everywhere: Xamarin and cross platform developmentC# everywhere: Xamarin and cross platform development
C# everywhere: Xamarin and cross platform developmentGill Cleeren
 
Getting started with jQuery
Getting started with jQueryGetting started with jQuery
Getting started with jQueryGill Cleeren
 
Top 10 HTML5 features
Top 10 HTML5 featuresTop 10 HTML5 features
Top 10 HTML5 featuresGill Cleeren
 
Comparing XAML and HTML: FIGHT!
Comparing XAML and HTML: FIGHT!Comparing XAML and HTML: FIGHT!
Comparing XAML and HTML: FIGHT!Gill Cleeren
 
Why you shouldn't dismiss windows 8 for your lob apps
Why you shouldn't dismiss windows 8 for your lob appsWhy you shouldn't dismiss windows 8 for your lob apps
Why you shouldn't dismiss windows 8 for your lob appsGill Cleeren
 
Advanced MVVM in Windows 8
Advanced MVVM in Windows 8Advanced MVVM in Windows 8
Advanced MVVM in Windows 8Gill Cleeren
 

Mais de Gill Cleeren (12)

Continuous integration and delivery with Xamarin and VSTS
Continuous integration and delivery with Xamarin and VSTSContinuous integration and delivery with Xamarin and VSTS
Continuous integration and delivery with Xamarin and VSTS
 
Real world apps with Xamarin and MVVM
Real world apps with Xamarin and MVVMReal world apps with Xamarin and MVVM
Real world apps with Xamarin and MVVM
 
Hello windows 10
Hello windows 10Hello windows 10
Hello windows 10
 
Bootstrap: the full overview
Bootstrap: the full overviewBootstrap: the full overview
Bootstrap: the full overview
 
Top 10 HTML5 features every developer should know!
Top 10 HTML5 features every developer should know!Top 10 HTML5 features every developer should know!
Top 10 HTML5 features every developer should know!
 
Building a community - BuildStuff Lithuania 2014
Building a community - BuildStuff Lithuania 2014Building a community - BuildStuff Lithuania 2014
Building a community - BuildStuff Lithuania 2014
 
C# everywhere: Xamarin and cross platform development
C# everywhere: Xamarin and cross platform developmentC# everywhere: Xamarin and cross platform development
C# everywhere: Xamarin and cross platform development
 
Getting started with jQuery
Getting started with jQueryGetting started with jQuery
Getting started with jQuery
 
Top 10 HTML5 features
Top 10 HTML5 featuresTop 10 HTML5 features
Top 10 HTML5 features
 
Comparing XAML and HTML: FIGHT!
Comparing XAML and HTML: FIGHT!Comparing XAML and HTML: FIGHT!
Comparing XAML and HTML: FIGHT!
 
Why you shouldn't dismiss windows 8 for your lob apps
Why you shouldn't dismiss windows 8 for your lob appsWhy you shouldn't dismiss windows 8 for your lob apps
Why you shouldn't dismiss windows 8 for your lob apps
 
Advanced MVVM in Windows 8
Advanced MVVM in Windows 8Advanced MVVM in Windows 8
Advanced MVVM in Windows 8
 

Último

W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 

Último (20)

Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 

Building your first android app using Xamarin

  • 1.
  • 2. Building your first Android app using Xamarin Gill Cleeren - @gillcleeren
  • 3. Hi, I’m Gill! Gill Cleeren MVP and Regional Director .NET Practice Manager @ Ordina Trainer & speaker @gillcleeren gill@snowball.be
  • 4. I’m a Pluralsight author! • Courses on Windows 8, social and HTML5 • http://gicl.me/mypscourses
  • 5. Agenda • Overview of Xamarin and Xamarin.Android • Xamarin.Android fundamentals • Creating a detail screen • Lists and navigation • Navigating from master to detail • (Optional) Intro to using Fragments • Optimizing the application • Preparing for store deployment
  • 6. Targets of this talk • Understanding the fundamentals of Android app development with Xamarin • See how a fully working app can be built
  • 7. The demo scenario • Android Coffee Store Manager • List of coffee • Navigation to details page
  • 8. DEMO Looking at the finished application
  • 9. Overview of Xamarin and Xamarin.Android
  • 10. Hello Xamarin • Xamarin enables developers to reach all major mobile platforms! • Native User Interface • Native Performance • Shared Code Across Platforms • C# & .NET Framework • Toolset on top of Visual Studio • Enables VS to create native iOS and Android apps • Commercial product
  • 11. Write Everything in C# iOS, Android, Windows, Windows Phone, Mac Billions of Devices covered!
  • 12. The Xamarin platform Xamarin Xamarin.Android Xamarin.iOS Xamarin Forms
  • 13. Xamarin.Android exposes many extra device types
  • 14. Xamarin.Android Anything you can do in Java/Android can be done in C# and Visual Studio (or Xamarin Studio) with Xamarin!
  • 15. How Xamarin works on Android • Mono VM + Java VM execute side-by-side (supports both Dalvik and ART) • Mono VM JITs IL into native code and executes most of your code • Can utilize native libraries directly as well as .NET BCL
  • 16. A word on code-sharing • Xamarin brings development time through the use of code-sharing • Possible (currently!) using • Shared projects: • allows organizing the shared code • #if directives for platform specific code • PCL • “include” the platforms we want to support • Abstract to interfaces where platforms have specific implementations
  • 17. Target architecture for a Xamarin app
  • 19. What you need for Xamarin.Android development • Xamarin license (Xamarin.Android) • PC or Mac • Visual Studio or Xamarin Studio • Android SDK and Emulators (installed via Xamarin setup) • Emulator • Device (not really required but...)
  • 21. A word on emulators • Setup will install some basic emulators for you • They’re great… for drinking a lot of coffee
  • 22. Alternatives for the default emulators • Possible options • Genymotion -Requires VirtualBox under the hood • HAXM drivers • Android Player from Xamarin • Microsoft Android emulator • Hyper-V
  • 23. Developing with a device • 3 steps • Enable Debugging on the Device • Install USB Drivers (Windows only) • Connect the Device to the Computer
  • 24. Enable device debugging • Tap the Build number 7 times to reveal developer options
  • 25. DEMO A quick look at the development setup
  • 27. File  New Project
  • 28. File  New Project
  • 29. Fundamental #1: Activities • Apps are collections of activities • A view == an activity (for now ) • Apps don’t have an “entry point” • No single code line which is called by the OS • Apps start when Android creates one of the classes of the app • App then gets loaded into memory
  • 30. Fundamental #1: Activities • When opening an application, the OS creates the first Activity • Activity is a specific class • Defines UI and behaviour for a single task • Corresponds to a single app screen • App gets loaded in memory OS User launches app Activity Android loads app In memory
  • 31. Fundamental #1: Activities • One activity needs to be the “entry point” for the app: MainLauncher=True
  • 33. Activity lifecycle • We can of course override these methods • OnCreate: • Create views, initialize variables, and do other prep work before the user sees the Activity • This method is called only once when the Activity is loaded into memory • OnResume • Perform any tasks that need to happen every time the Activity returns to the device screen • OnPause • Perform any tasks that need to happen every time the Activity leaves the device screen
  • 35. Fundamental #2: Views • The layout of the app is contained in *.axml files • AXML: Android designer file / Android XML • First view of the app is named Main.axml • Can be any name really • AXML files live in the Resources/layout folder
  • 36. The designer for Xamarin.Android views
  • 37. The designer for Xamarin.Android views
  • 39. Connecting and accessing controls from code • Linking a view with an activity is done using SetContentView
  • 40. Connecting and accessing controls from code • We can name controls using the ID property • The Android designer maps the control to the Resource class and assigns it a resource ID • The code representation of a control is linked to the visual representation of the control in the designer via the Id property
  • 41. Connecting and accessing controls from code • Once we have created the controls, we can access them from code • Field name is used for lookup
  • 42. Fundamental #3: Application manifest • An Android app contains a manifest file • Contains a list of all resources, properties… that make up the application • Also contains name, list of permissions… that the application has received Images Icons *.axml Others Android Manifest file
  • 43.
  • 44. DEMO Creating our first Android application together!
  • 46. Fundamental #4: ListViews and adapters • Used very commonly in Android • Common way to present lists of rows • Each row is represented using a standard style or customized • Consists out of • ListView: visual part • Adapter: feeds data to ListView
  • 48. Important classes • ListView • ListActivity • BaseAdapter • ArrayAdapter & ArrayAdapter<T>
  • 49. ListActivity and the built-in ArrayAdapter<T> [Activity(Label = "Coffees", MainLauncher = true, Icon = "@drawable/icon")] public class CoffeeScreenActivity: ListActivity { string[] coffees; protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); coffees= new string[] { "Coffee 1","Coffee 2", "Coffee 3"}; ListAdapter = new ArrayAdapter<String>( this, Android.Resource.Layout.SimpleListItem1, coffees); } }
  • 50. Implementing your own adapter • In most cases, the ArrayAdapter won’t be enough • We’ll need to create our own adapter • Inherits from BaseAdapter • Things we need to implement • Count: • To tell the control how many rows are in the data • GetView: • To return a View for each row, populated with data. This method has a parameter for the ListView to pass in an existing, unused row for re-use • GetItemId: • Return a row identifier (typically the row number, although it can be any long value that you like) • this[int] indexer: • To return the data associated with a particular row number
  • 51. Handling row clicks • To handle row clicks, we need to implement OnListItemClick protected override void OnListItemClick(ListView l, View v, int position, long id) { var t = items[position]; //do something }
  • 52. DEMO Adding a ListView and an adapter
  • 53. Customizing the ListView with other row views
  • 54. Customizing the ListView with other row views
  • 55. Customizing the ListView with other row views
  • 57. Creating your own row views • Custom row layouts are AXML files in Resources/layout • Are loaded by Id using a custom adapter • View can contain any number of display classes with custom colors, fonts…
  • 58. Creating your own row view <?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="wrap_content" android:padding="8dp" android:orientation="horizontal"> <ImageView android:id="@+id/CoffeeImageView" android:layout_width="50dp" android:layout_height="50dp" android:padding="5dp" /> <LinearLayout android:id="@+id/TextFields" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingLeft="10dip"> <TextView android:id="@+id/CoffeeNameText" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:id="@+id/PriceText" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout> </LinearLayout>
  • 59. Using your custom row view public override View GetView(int position, View convertView, ViewGroup parent) { //custom view var item = items[position]; if (convertView == null) { convertView = context.LayoutInflater.Inflate (Resource.Layout.CoffeeRowView, null); } convertView.FindViewById<ImageView> (Resource.Id.CoffeeImageView).SetImageResource( imageRepository.ImageNameToResourceInt(item.ImageId.ToString())); convertView.FindViewById<TextView> (Resource.Id.CoffeeNameText).Text = item.CoffeeName; convertView.FindViewById<TextView> (Resource.Id.PriceText).Text = item.Price.ToString(); return convertView; }
  • 60. DEMO Adding our own custom row view
  • 61. Fundamental #5: Intents • An Intent is an abstract concept for some sort of operation that should be performed in Android • Navigating to another activity • Often, launching an external application (= built-in) with the intent of doing something • Make a phone call • Launch a URI • Map an address • An intent often consist out of • What the intent is • The data needed for the intent • Phone number to call
  • 62. Intent of making a phone call • ActionCall asks Android for an Activity to make a phone call
  • 63. Intent of navigating to another screen • StartActivity can be used to start another activity • PutExtra() is used to pass data from one activity to the other var intent = new Intent (); intent.SetClass (this, typeof(CoffeeDetailActivity)); intent.PutExtra ("selectedCoffeeId", t.CoffeeId); StartActivity (intent);
  • 64. Receiving information from the intent protected override void OnCreate (Bundle bundle) { base.OnCreate (bundle); SetContentView (Resource.Layout.Main); var selectedCoffeeId = Intent.Extras.GetInt ("selectedCoffeeId", 0); Coffee coffee = DataService.GetCoffeeById (selectedCoffeeId); }
  • 65. DEMO Navigating from the List to the Detail page
  • 67. The need for Fragments • Larger screen: more complex to build UIs that look good on all screens • Layouts which look good on a small screen may not look good on a large tablet screen • Android V3.0 introduced Fragments • Fragment is a UI module • UI gets divided into reusable parts • Each “part” is an separate activity • At run time, the Activities themselves will decide which Fragments to use • Also work in older versions through Support packages
  • 68. The need for Fragments
  • 69. FragmentManager • To help an Activity coordinate and manage all these Fragments, Android introduced a new class called the FragmentManager • Each activity has an instance of the FragmentManager • Allows finding, adding and removing fragments
  • 70. Adding a fragment to an Activity • We can add the Fragment to the Activity in 2 ways • Declaratively: • Fragments can be used declaratively within .axml layout files by using the <Fragment> tag • Programmatically • Fragments can also be instantiated dynamically by using the FragmentManager class’s API
  • 73. Managing strings in strings.xml • We can have Android store string values for us <?xml version="1.0" encoding="utf-8"?> <resources> <string name="hello">Hello World, Click Me!</string> <string name="app_name">AndroidCoffeeStore</string> <string name="coffeeNameLabel">Coffee name</string> </resources> <TextView android:text="@string/coffeeNameLabel" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/CoffeeNameLabel" />
  • 74. Making the app multi-language
  • 75. Application drawables • We can add drawables: application icons • Adding all resolutions makes sure the icons look good on all screens • Filenames are the same • Folder name identifies the resolution
  • 76. Application drawables • We can select an image in the project properties • This now becomes the icon for the application within Android
  • 79. Publishing your work • Marketplace is most common option • Often, more than one is used (Google Play, Amazon, GetJar…) • Email or website is often for a more closed distribution • Also require less work to prepare the application for distribution • Google Play is best known store • Allows users to discover, download, rate, and pay for applications by clicking a single icon either on their device or on their computer • Google Play also provides tools to assist in the analysis of sales and market trends and to control which devices and users may download an application
  • 80. Summary • Xamarin.Android leverages your C# knowledge to build apps for Android • Concepts of Android mean a learning curve
  • 82. Q&A
  • 83. Building your first Android app using Xamarin Gill Cleeren - @gillcleeren
  • 84. Your feedback is important! Scan the QR Code and let us know via the TechDays App. Laat ons weten wat u van de sessie vindt via de TechDays App! Scan de QR Code. Bent u al lid van de Microsoft Virtual Academy?! Op MVA kunt u altijd iets nieuws leren over de laatste technologie van Microsoft. Meld u vandaag aan op de MVA Stand. MVA biedt 7/24 gratis online training on-demand voor IT- Professionals en Ontwikkelaars.