You’re a smart guy, figure it out!

Mike Grushin’s thoughts on everything tech-related and more…

Xamarin Evolve 2013–Training Days

Posted by mikeg on April 16, 2013

Overview

We are done with 2 days of Xamarin training sessions – conference itself starts tomorrow. So far very much impressed with the technology and the company itself – everyone we’ve met seems to be very knowledgeable, friendly and really enjoying what they do. Sounds like a recipe for success. A few general comments:

  • While Xamarin technology allows C# developers to develop native mobile apps, there is still a pretty steep learning curve for web developers. Web developers are used to dealing with single-page requests where native app development is very different – dealing with performance, responsiveness, background threads, various hardware, etc makes it a lot more complex
  • With that said the fact that C# and general .net knowledge can be reused is very powerful – especially the fact that developers can continue working in arguably the best development environment (Visual Studio 2012)
    • Task Parallel Library is a very convenient way to handle async tasks and seems a lot simpler than native iOS/Android approaches
    • Code sharing and using nunit for unit testing of shared code is great
    • Xamarin Component Marketplace holds a lot of promise in making development easier – I expect vendors (possibly available already) such as Telerik and Infragistics start offering XPlat components that will further increase code reuse while look native on respective OSes

Below are notes from the sessions – mostly useful/interesting links/comments that were made during the sessions

 

MVC

  • MVC was created in 1979
  • iOS approach to MVC:
  • Controller
    • Wires Everything together
    • Listens for Requests from View
    • Manages Other Controllers
    • Populate View from Model
  • Views and Controllers in iOS
    • Responsible for UI in CocoaTouch
    • Views and Controllers – UIKit
      • UIViewController – just a controller, slightly confusing name
      • UIView
    • First Controller = Root Controller
  • Navigation Controller
    • UINavigationController – controller has its own UI (navigation bar)
      • Hooks for Forward Navigation
      • Title Bar and Back Button
    • Other methods of Navigation
      • Tab Bar Controller
      • Split View Controller
  • PushViewController
    • Segues are Great, but won’t work for everything
      • Dynamically loaded screens
      • Screens defined in Code
    • Have to Push Programmatically
    • NavigationController.PushViewController

Tables in iOS

  • Most commonly used – anything that looks like a list is likely to be a table, including “grouped” lists
  • overview
    • UITableView
    • UITableViewCell
    • UITableViewSource – this is what usually is used to connect to Model
    • NSIndexPath – a reference to section and row of what was “touched”
    • UITableViewController
  • layoutSubviews() – robust way of laying out content to react to different screen sizes , rotation, edit mode

Android

Cross-Platform Navigation

  • Navigating Stacks  – “back stack”
    • iOS – “local” to the stack you are in
    • Android – used to be hardware button
    • Windows – hardware button
  • Tab Alternatives – Satellite Menu (Path app)

image

Introduction to Cross-Platform Development and Visual Studio

  • UX in iOS != Android != Windows Phone
  • UX Metaphors are different
    • Navigation Controller vs. Back Button
  • Write-Once, Run-Anywhere is Problematic – Users Expect Native UX
  • Minimize Device Targets
    • Start with single OS first and then add additional
  • For Android, focus on top 5 phones at that time
  • Develop with Xplat Architecture
    • Good Architecture will Maximize Code Reuse
    • More expensive to change later
  • Code-Sharing Options
    • Two Major Options
      • File Linking
      • Portable Class Libraries (PCL)
    • File Linking is Generally Recommended (easier to setup, not architecturally pure)
    • PCL support is still under dev and complicated to setup and use
  • File Linking
    • Easy
    • can use conditional compilation
    • note: in visual studio there is “project linker” extension that makes this easy
    • also able to share folders, not just individual files
  • Platforms + Devices vary widely
    • File locations for DBs, etc
    • Some shared code needs to be platform-aware
  • Devices differ widely, even within a platform
    • hardware features: camera, compass, nfc
    • form factor: screen sizes, ratio, density
    • API differences between hardware vendors
    • check for device feature before using
  • Conditional Compilation (page 12 in PDF)
  • use sqllite.net orm
    • tasky pro shows how to access DB 
  • Architectural Abstraction
    • Inheritance/Polymorphism
      • Interfaces
      • Virtual Classes
    • Provider Pattern
    • Inversion of Control (Simple Dependency) – same as provider pattern
  • Cross-Platform Libraries
    • Xamarin.Mobile & Xamarin.Social
    • Monotouch.Dialog
    • Third-party libraries
      • MonoCross (http://www.monocross.net) cross platform forms
      • MvvmCross
      • Vernacular – localization library build by rdio
      • MonoGame – XNA port
  • Visual Studio Highlights
    • Can use one solution for iOS, Android and Windows
    • Android dev is nearly identical to Xamarin Studio
    • iOS is somewhat different

Web Services

  • System.Net.WebClient – blocks main thread
  • Json.NET – robust library for JSON
    • ServiceStack.Text – small quick
  • Calling Async
    • *Async versions of methods. Example: WebClient.DownloadDataAsync()
    • Start a background thread
    • Task Parallel Library (TPL) – Recommended
  • object stores
    • Axure Mobile Services
    • ServiceStack
    • Parse

Components & Social

  • Add awesome functionality quickly from the Xamarin Component Store
  • Xamarin.Mobile
    • Photo Library & Camera
    • Image Filtering
    • Access to Social Networks
    • Address Book
    • Email

Patterns

  • Data Transfer Object – simple, properties only
  • Adapter – translate a class interface to a different interface that is required by the consumer
  • Façade (or Manager) – encapsulates complex logic in a simple, higher-level API
  • Provider – build multiple implementations of an API for use in different scenarios (or on different platforms)
  • Model View Controller
    • View and Controller are usually platform specific
    • Model – Shared (might include Façade)
  • Model View View Model (Microsoft)
    • View – Platform Specific
    • ViewModel & Model – Shared
    • it’s like an adapter
  • Field Service pre-build app – MVVM example (TODO: review)
  • XPlan UI
  • Maximize Shared Code
    • SQLite-NET
    • Web Services
    • Business Logic
    • Input Validation
    • File Operations (& caching)
    • Background Tasks
    • Localization

Memory and Performance Best Practices

  • Reducing Pressure on Garbage Collector
    • Two things to care about
      • How often collections Occur
      • How long they take – depends on the size of the objects (t-shirts vs winter coat analogy)
    • Generational vs Non-Generational GC
    • Avoiding Collections
  • Be careful with container.AddSubview() – creates Strong Reference
  • Dealing with Strong Reference Cycles
    • Set Link to Container to Null
    • Remove Contained Object From Container
    • Call Dispose on the Objects
    • Use WeakReference<T>
  • Avoiding Strong Reference Cycles
    • Remove Event Handlers When Done ( –=)
    • NSObject-derived Classes Shouldn’t Keep Strong Reference to Parents
    • NSObjects Shouldn’t Keep Strong References to other NSObject Ancestors
  • Reducing App Size
    • Don’t build with “Don’t Link”
    • Build for Single Architecture (ARMv7)
    • Don’t enable debug
    • Use LLVM Compiler for release – slower but worth it from app size
    • Link All Assemblies
    • Create shared code
  • Creating Responsive Apps – recommendation to use TPL
  • Additional Performance Tips
    • Avoid Garbage Collection in Tight Loops
    • Use SQLite.NET
    • Test on All Platforms
  • iOS Specific Tips
    • Performance Considerations
      • Emulator vs Device – always profile/optimize on the device
      • Screen refresh rates for games
      • Core Animation performance hits
      • Avoid code generation – while your code doesn’t do it, library you are using might so need to test
  • Profiling/Diagnostics
    • Tools menu in Xamarin Studio – Launch Instruments
      • iOS – Memory – Allocations
      • Choose Target – choose app
      • Use search bar to search for specific type (UIImage)
    • CPU analysis can point to C# code
About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.

Join 183 other followers

%d bloggers like this: