Xamarin in Action
Creating native cross-platform mobile apps
Jim Bennett
  • MEAP began September 2016
  • Publication in Early 2018 (estimated)
  • ISBN 9781617294389
  • 450 pages (estimated)
  • printed in black & white

Xamarin is a toolset that allows you to write native mobile apps in C# and run them on both iOS and Android devices. What makes Xamarin stand out from other cross-platform tools is that it gives you the ability to share large portions of code across these two platforms while still letting you write native apps that can take full advantage of the device and OS features specific to each platform. And since Xamarin was recently acquired by Microsoft, you can be sure the ecosystem will continue to grow - Xamarin has become a hugely important part of Microsoft's "any developer, any platform" mantra.

Xamarin in Action teaches you how to build Xamarin apps on iOS and Android from scratch while maximizing code re-use. This layer-by-layer guide starts by showing you the MVVM design pattern and explaining how it increases code sharing. Next, you'll start building an app from the ground up. You'll learn all the different layers inside a well written Xamarin app and discover how most of your code can be shared between iOS and Android. You'll look at how this code sharing can be best designed to allow unit testing of your business layer as well as your UI logic. Then you'll dig in to code that can't be shared, like user interface code that's device specific. Finally, you'll learn how to take your app from final code to a tested and deployed version on the relevant store. By the end, you'll be able to build a high quality production-ready Xamarin app on iOS and Android from scratch with a high level of code reuse.

"Easily the best and most comprehensive resource available on Xamarin development. Based on the initial 8 chapters, I do not think the author has left anything uncovered."

~ Krishna Anipindi

"The book deals with two most important upcoming trends in IT, mobile development and code reuse (across platform). The knowledge in these 2 fields go a long way together. The author demonstrates a good understanding of these 2 topics and clubbed with the practical examples, this book stands true to its name...it'll get you in action."

~ Prabhuti Prakash

"A clearly written and informative guide on how to get up and running creating your own cross platform apps using Xamarin."

~ Eric Sweigard

Table of Contents detailed table of contents

Part 1: Getting started with native cross-platform apps

1. Introducing native cross-platform applications with Xamarin

1.1. Introduction to Xamarin mobile apps

1.1.1. Vendor-specific native apps

1.1.2. Cordova

1.1.3. Xamarin native apps

1.1.4. Xamarin.Forms

1.1.5. Xamarin Developer tools

1.2. Mobile-optimized developer lifecycle

1.3. Introduction to production quality apps

1.3.1. Design

1.3.2. Source code control

1.3.3. Develop

1.3.4. Test

1.3.5. Build

1.3.6. Distribute

1.3.7. Monitor

1.4. Rinse and repeat…

1.5. Summary

2. Hello MVVM — creating a simple cross-platform app using MVVM

2.1. What are UI design patterns?

2.1.1. Model-View-Controller

2.1.2. Model-View-Presenter

2.2. MVVM - the design pattern for Xamarin apps

2.3. What is Cross-platform code?

2.3.1. Portable Class libraries

2.3.2. Using PCLs to access device specific code

2.4. Getting started - creating your first solution

2.4.1. Requirements - what hardware or software do you need for each mobile platform?

2.4.2. Creating the solution

2.4.3. So what have we just created?

2.4.4. Building and running the apps

2.5. Is this really a cross-platform app?

2.6. Summary

3. MVVM — the Model-View-View Model design pattern

3.1. The Model layer

3.1.1. The code should be cross-platform

3.1.2. The code should be testable

3.1.3. The model should represent data and business logic at the domain level not the UI level

3.2. The View Model layer

3.2.1. State and behavior

3.2.2. Value conversion

3.2.3. Testability

3.3. The View layer

3.4. Binding

3.4.1. Source and target

3.4.2. Binding mode

3.4.3. Binding is not cross-platform

3.4.4. Value converters

3.5. The Application layer

3.6. Navigation

3.6.1. View first

3.6.2. View model first

3.6.3. Which one to use?

3.7. Let's revisit our square root calculator app as a whole

3.8. Summary

4. Hello Again MVVM — understanding and enhancing our simple MVVM app

4.1. A deeper dive into our Hello Cross—Platform World app

4.1.1. The model

4.1.2. The view model

4.1.3. The application layer

4.1.4. The view

4.2. Expanding on our Hello World app

4.2.1. Installing the Xamarin Text To Speech plugin

4.2.2. Adding the cross—platform code

4.2.3. Inversion of control

4.2.4. Wiring up the Android UI

4.2.5. Wiring up the iOS UI

4.2.6. Let's review the changes

4.3. Summary

5. What are we (a)waiting for? An introduction to multi-threading for Xamarin apps

5.1. Why do we need multi-threaded code?

5.2. What are threads?

5.2.1. Buying coffee

5.2.2. So what is a thread?

5.2.3. Quick round-up

5.3. UI thread and background threads

5.3.1. The UI thread

5.3.2. Background threads

5.4. Using tasks to run code in the background

5.4.1. Task and Task<T>

5.4.2. Chaining tasks

5.5. Task results

5.5.1. Polling to see if the task has finished

5.5.2. Waiting on the task

5.5.3. Getting the result from a continuation

5.5.4. Task exceptions

5.6. Updating the UI

5.6.1. The UI task scheduler

5.6.2. Using the power of MVVM

5.7. Async and await

5.7.1. The async and await keywords

5.7.2. Writing your own async methods

5.7.3. Async commands

5.8. Make your app feel responsive

5.9. The foundations have been laid, now its time to start building things

5.10. Summary

Part 2: From blank solution to an empty, working app

6. Designing MVVM cross-platform apps

6.1. Introduction to designing our cross-platform app

6.2. Designing the UI and user flows

6.2.1. SquareRt - a simple app for calculating square roots

6.2.2. Countr - an app for counting multiple things

6.2.3. Defining user flows and UIs

6.3. Architecting our app

6.3.1. Which layer?

6.3.2. Which thread?

6.3.3. Mapping your code to layers and threads

6.4. Creating the solutions

6.5. Application properties

6.5.1. Android manifest

6.5.2. iOS info.plist

6.6. SDK versions

6.6.1. Android SDK versions and the SDK manager

6.6.2. iOS SDK versions

6.7. Linking

6.7.1. Linking our apps

6.7.2. Linker options

6.7.3. Stopping the linker doing too much

6.8. Summary

7. Building cross-platform models

7.1. Building simple model layers

7.2. Unit testing

7.2.1. Creating a unit test project

7.2.2. Creating our first test

7.2.3. What do these tests tell us?

7.3. Building more complex model layers

7.3.1. Services, data models and repositories

7.3.2. Accessing databases

7.3.3. Adding a service layer

7.3.4. Accessing web services

7.4. A recap

7.5. Summary

8. Building cross-platform view models

8.1. The view model layer

8.1.1. The view model layer inside SquareRt

8.1.2. The view model layer inside Countr

8.2. Adding state and behavior to SquareRt

8.2.1. State inside SquareRt

8.2.2. Exposing behavior via property changes

8.3. Adding state and behavior to Countr

8.3.1. Single value properties

8.3.2. Collections

8.3.3. Exposing behavior using commands

8.3.4. Messaging

8.3.5. Navigation

8.4. Summary

9. Building platform specific views - Android

9.1. Building the UI for SquareRt

9.1.1. Layout files

9.1.2. Resources

9.1.3. Resource locations

9.1.4. Editing layout files

9.1.5. Layout inflation

9.2. Creating the layout file for the SquareRt UI

9.2.1. Adding our toolbar

9.2.2. Adding our image

9.2.3. Adding an edit text

9.2.4. Adding the result text view

9.3. Building the SquareRt view

9.3.1. What is an Activity

9.3.2. The Activity lifecycle

9.3.3. Creating the Activity for the view

9.3.4. Running the app

9.4. Building the UI for Countr

9.4.1. Creating the UI for the master view

9.4.2. Recycler Views

9.4.3. Creating the UI for the Recycler View items

9.4.4. Floating action buttons

9.4.5. Creating the UI for the detail view

9.4.6. Menu items

9.5. Building the Countr views

9.5.1. Setting up master recycler views

9.5.2. The detail view

9.5.3. Running the app

9.6. Summary

10. Building platform specific views - iOS

10.1. Building iOS UIs

10.1.1. Storyboards

10.1.2. Controls

10.1.3. Different screen resolutions

10.1.4. Auto Layout with Constraints

10.1.5. Image resources and asset catalogs

10.1.6. A quick recap

10.2. Creating the SquareRt storyboard

10.2.1. Adding our first view controller

10.2.2. Adding an image

10.2.3. Adding a text field

10.2.4. Adding the result label

10.2.5. Seeing the layout on different devices

10.2.6. Size classes

10.2.7. A quick recap

10.3. Building the SquareRt view

10.3.1. What is a view controller

10.3.2. View lifecycle

10.3.3. Creating the view controller

10.3.4. Wiring up controls to the view controller

10.3.5. Binding the view controller

10.3.6. Another quick recap

10.3.7. Running the app

10.4. Building the UI and view controllers for Countr

10.4.1. Creating the UI for the master view

10.4.2. Navigation bars and buttons

10.4.3. Creating the UI for the detail view

10.4.4. Another recap

10.4.5. Running the app

10.5. Summary

11. Running the app

Part 3: From a working app to a production ready app

12. Testing the app using UITest

13. Instrumentation and monitoring

14. Deploying the app

Appendixes:

Appendix A: What are design patterns anyway?

Appendix B: Using someone else's code

Appendix C: UI flows and threads for SquareRt and Countr

What's inside

  • Understand MVVM and how it maximizes code reuse and testability
  • Build a mobile app from rough design through final deployable product
  • Creating cross platform model and UI logic layers
  • Build device specific UIs for iOS and Android
  • Test apps through unit and automated UI testing
  • Prepare apps for publication with user tracking and crash analytics

About the reader

This book is for C# developers with a few months through many years of experience who want to build native mobile apps for iOS and Android using the language and toolset they already know.

About the author

Jim Bennett is a Xamarin MVP, Microsoft MVP, Xamarin Certified Developer and an active community member.. He's also a frequent speaker at events all around the world, including Xamarin user groups and Xamarin and Microsoft conferences. He regularly blogs about Xamarin development at https://jimbobbennett.io.

Manning Early Access Program (MEAP) Read chapters as they are written, get the finished eBook as soon as it’s ready, and receive the pBook long before it's in bookstores.
Buy
MEAP combo $49.99 pBook + eBook
MEAP eBook $39.99 pdf + ePub + kindle

FREE domestic shipping on three or more pBooks