O slideshow foi denunciado.
Utilizamos seu perfil e dados de atividades no LinkedIn para personalizar e exibir anúncios mais relevantes. Altere suas preferências de anúncios quando desejar.
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@sn...
I’m a Pluralsight author!
• Courses on Xamarin, WPF, social and HTML5
• http://gicl.me/mypscourses
Agenda
• Overview of Xamarin and Xamarin.Android
• Xamarin.Android fundamentals
• Creating a detail screen
• Lists and nav...
Targets of this talk
• Understanding the fundamentals of Android app development with
Xamarin
• See how a fully working ap...
The demo scenario
• Android Coffee Store Manager
• List of coffees
• 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 Performan...
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 int...
A word on code-sharing
• Xamarin brings development time through the use of code-sharing
• Possible (currently!) using
• S...
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 S...
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
...
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 “...
Fundamental #1: Activities
• When opening an application, the OS creates the first Activity
• Activity is a specific class...
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 othe...
Activity lifecycle in effect
Fundamental #2: Views
• The layout of the app is contained in *.axml files
• AXML: Android designer file / Android XML
• F...
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 c...
Connecting and accessing controls from code
• Once we have created the controls, we can access them from code
• Field name...
Fundamental #3: Application manifest
• An Android app contains a manifest file
• Contains a list of all resources, propert...
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...
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")]
...
Implementing your own adapter
• In most cases, the ArrayAdapter won’t be enough
• We’ll need to create our own adapter
• I...
Handling row clicks
• To handle row clicks, we need to implement OnListItemClick
protected override void OnListItemClick(L...
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 adap...
Creating your own
row view
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/...
Using your custom row view
public override View GetView(int position, View convertView, ViewGroup parent)
{
//custom view
...
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
...
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 ...
Receiving information from the intent
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
SetConten...
DEMO
Navigating from the List
to the Detail page
Optimizing
the application
Managing strings in strings.xml
• We can have Android store string values for us
<?xml version="1.0" encoding="utf-8"?>
<r...
Making the app multi-language
Application drawables
• We can add drawables: application icons
• Adding all resolutions makes sure the icons look good on...
Application drawables
• We can select an image in the project properties
• This now becomes the icon for the application w...
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…)
• E...
Summary
• Xamarin.Android leverages your C# knowledge to build apps for
Android
• Concepts of Android mean a learning curve
Thanks!
Q&A
VISUG Partners
Building your first Android app
using Xamarin
Gill Cleeren
@gillcleeren
Building your first android app using xamarin (Gill Cleeren)
Próximos SlideShares
Carregando em…5
×

Building your first android app using xamarin (Gill Cleeren)

694 visualizações

Publicada em

Do you have a great knowledge about C#? Maybe you’ve already built a great mobile app on Windows Phone or Windows 8 or even Windows 10? Would you like to be able to use your knowledge to build an Android app without having to resort to other languages or IDEs? This is possible using Xamarin! In this session, Gill Cleeren will take you through the creation of your first Android application: Joe’s Coffee Store. Along the way, you will learn the basic concepts of Android such as Activities and see how we can use these from Xamarin.Android. We’ll need to connect with services to get access to data and we’ll learn how to navigate in the app. You’ll see we can do this all of this directly from Visual Studio. We will finish the session by looking at how we can deploy the application to the Google Play Store so it’s ready for our users! You’ll walk away wanting to port your code to Android!

Publicada em: Tecnologia
  • How to Grip Her Attention - Unlock Her Legs ◆◆◆ http://t.cn/AiurDrZp
       Responder 
    Tem certeza que deseja  Sim  Não
    Insira sua mensagem aqui
  • Unlock Her Legs is your passage way to a life full of loving and sex... read more ... ♥♥♥ http://ishbv.com/unlockher/pdf
       Responder 
    Tem certeza que deseja  Sim  Não
    Insira sua mensagem aqui
  • ★★ How Long Does She Want You to Last? ★★ A recent study proved that the average man lasts just 2-5 minutes in bed (during intercourse). The study also showed that many women need at least 7-10 minutes of intercourse to reach "The Big O" - and, worse still... 30% of women never get there during intercourse. Clearly, most men are NOT fulfilling there women's needs in bed. Now, as I've said many times - how long you can last is no guarantee of being a GREAT LOVER. But, not being able to last 20, 30 minutes or more, is definitely a sign that you're not going to "set your woman's world on fire" between the sheets. Question is: "What can you do to last longer?" Well, one of the best recommendations I can give you today is to read THIS report. In it, you'll discover a detailed guide to an Ancient Taoist Thrusting Technique that can help any man to last much longer in bed. I can vouch 100% for the technique because my husband has been using it for years :) Here's the link to the report ◆◆◆ https://tinyurl.com/rockhardxx
       Responder 
    Tem certeza que deseja  Sim  Não
    Insira sua mensagem aqui

Building your first android app using xamarin (Gill Cleeren)

  1. 1. Building your first Android app using Xamarin Gill Cleeren @gillcleeren
  2. 2. Hi, I’m Gill! Gill Cleeren MVP and Regional Director .NET Practice Manager @ Ordina Trainer & speaker @gillcleeren gill@snowball.be
  3. 3. I’m a Pluralsight author! • Courses on Xamarin, WPF, social and HTML5 • http://gicl.me/mypscourses
  4. 4. Agenda • Overview of Xamarin and Xamarin.Android • Xamarin.Android fundamentals • Creating a detail screen • Lists and navigation • Navigating from master to detail • Optimizing the application • Preparing for store deployment
  5. 5. Targets of this talk • Understanding the fundamentals of Android app development with Xamarin • See how a fully working app can be built
  6. 6. The demo scenario • Android Coffee Store Manager • List of coffees • Navigation to details page
  7. 7. DEMO Looking at the finished application
  8. 8. Overview of Xamarin and Xamarin.Android
  9. 9. 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
  10. 10. Write Everything in C# iOS, Android, Windows, Windows Phone, Mac Billions of Devices covered!
  11. 11. The Xamarin platform Xamarin Xamarin.Android Xamarin.iOS Xamarin Forms
  12. 12. Xamarin.Android exposes many extra device types
  13. 13. Xamarin.Android Anything you can do in Java/Android can be done in C# and Visual Studio (or Xamarin Studio) with Xamarin!
  14. 14. 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
  15. 15. 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
  16. 16. Target architecture for a Xamarin app
  17. 17. Preparing for Android development
  18. 18. 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...)
  19. 19. Installing Xamarin.Android
  20. 20. A word on emulators • Setup will install some basic emulators for you • They’re great… for drinking a lot of coffee
  21. 21. Alternatives for the default emulators • Possible options • Genymotion -Requires VirtualBox under the hood • HAXM drivers • Android Player from Xamarin • Microsoft Android emulator • Hyper-V • Preferred option on Windows
  22. 22. DEMO A quick look at the development setup
  23. 23. Xamarin.Android fundamentals
  24. 24. File  New Project
  25. 25. File  New Project
  26. 26. 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
  27. 27. 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
  28. 28. Fundamental #1: Activities • One activity needs to be the “entry point” for the app: MainLauncher=True
  29. 29. Activity lifecycle
  30. 30. 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
  31. 31. Activity lifecycle in effect
  32. 32. 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
  33. 33. The designer for Xamarin.Android views
  34. 34. The designer for Xamarin.Android views
  35. 35. View code
  36. 36. Connecting and accessing controls from code • Linking a view with an activity is done using SetContentView
  37. 37. 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
  38. 38. Connecting and accessing controls from code • Once we have created the controls, we can access them from code • Field name is used for lookup
  39. 39. 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
  40. 40. DEMO Creating our first Android application together!
  41. 41. Navigation and lists
  42. 42. 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
  43. 43. Fundamental #4: ListViews and adapters
  44. 44. Important classes • ListView • ListActivity • BaseAdapter • ArrayAdapter & ArrayAdapter<T>
  45. 45. 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); } }
  46. 46. 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
  47. 47. 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 }
  48. 48. DEMO Adding a ListView and an adapter
  49. 49. Customizing the ListView with other row views
  50. 50. Customizing the ListView with other row views
  51. 51. Customizing the ListView with other row views
  52. 52. DEMO Using the built-in row views
  53. 53. 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…
  54. 54. 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>
  55. 55. 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; }
  56. 56. DEMO Adding our own custom row view
  57. 57. 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
  58. 58. Intent of making a phone call • ActionCall asks Android for an Activity to make a phone call
  59. 59. 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);
  60. 60. 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); }
  61. 61. DEMO Navigating from the List to the Detail page
  62. 62. Optimizing the application
  63. 63. 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" />
  64. 64. Making the app multi-language
  65. 65. 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
  66. 66. Application drawables • We can select an image in the project properties • This now becomes the icon for the application within Android
  67. 67. DEMO Adding resources and drawables to the application
  68. 68. Deploying to the store
  69. 69. 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
  70. 70. Summary • Xamarin.Android leverages your C# knowledge to build apps for Android • Concepts of Android mean a learning curve
  71. 71. Thanks!
  72. 72. Q&A
  73. 73. VISUG Partners
  74. 74. Building your first Android app using Xamarin Gill Cleeren @gillcleeren

×