Home Mobile Xamarin 4 By Example

Xamarin 4 By Example

By Matteo Bortolu , Engin Polat , Mark Radacz
books-svg-icon Book
eBook $35.99 $24.99
Print $43.99
Subscription $15.99 $10 p/m for three months
$10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime!
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
BUY NOW $10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime!
eBook $35.99 $24.99
Print $43.99
Subscription $15.99 $10 p/m for three months
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
About this book
The mobile app market is increasing exponentially every year. Xamarin Studio with its modern and powerful IDEs makes creating applications a lot easier by simplifying the development process. Xamarin will allow you and your team to create native applications by taking advantage of one of the most evolved programming language in the world: C#. This book will provide you with the basic skills you need to start developing mobile apps using C# and Xamarin. By working through the examples in each chapter, you will gain hands-on experience of creating a complete app that is fully functional by all means. Finally, you will learn to publish the app you created on the app market. Each project in this book will take you one step closer to becoming a professional app developer.
Publication date:
August 2016
Publisher
Packt
Pages
274
ISBN
9781785282904

 

Chapter 1. Getting Started with Xamarin

Ladies and gentlemen, this is Engin and Matteo and we are your chief flight attendants. On behalf of Xamarin Developers Crew, welcome aboard! This is a non-stop service from C# to multiplatform mobile development. Our flight time will be as long as you prefer. We will be exploring exciting examples, trying to cover all the basic and some advanced topics of mobile development. Now make sure your seat and desktop are in the most comfortable position. At this time, we request that all electronic devices be switched in to developer mode. You will find this and all the other useful information in the book located in front of you. We strongly suggest that you read it before take-off. If you have any questions, don't hesitate to e-mail us. We wish you all an enjoyable flight.

 

Take off


Before we learn what cross-platform is, we will explore the meaning of platform specific native apps.

A native app is an app that uses the native Software Development Kit (SDK), and compiles and runs on one specific platform.

It is usually developed using the default programming language of the SDK.

We can write a native iOS app using Xcode as Integrated Development Environment (IDE) and Objective-C/Swift as languages, taking advantage of the iOS SDK.

A native Android app is written using Eclipse or Android Studio as IDE, Java as language, and the Android SDK as development kit.

A native Windows Phone app is written using Visual Studio as IDE, C# as language, and .NET as Framework.

This is the classic way to develop apps and for some developers, it is still the best way.

Platform specific native development gives some advantages. The first is that we can rely on the OS manufacturer publishing stable updates and we can always be one of the first to use them.

Also, apps written with native tools and languages have performance, security and better user experience advantages. Hybrid apps basically mobile focused web apps built with HTML5 and JavaScript, wrapped in a native container. Native languages and tools (compilers, linkers, and so on) generates more platform specific and natural outputs (binaries). More platform specific binaries more performant apps, generally it means speed.

It also has disadvantages, such as:

  • We need to know three languages in order to develop the same app for the three platforms

  • We cannot share the business logic between different platforms and we need to develop and maintain three different business logics

  • The code of one platform is mostly not understandable to those who use the other platform

In big companies, the platform specific approach works because most of them have a lot of people dedicated to a project and probably they can afford three different teams. Each one of the teams usually works independently to develop the same app in each single platform. The iOS team cannot share a single line of code with the Android team nor the Windows Phone team, or vice versa. This is called the Silo approach.

People usually think about cross-platform mobile development as Write Once, Run Anywhere (WORA approach).

The main advantage of this approach is that we can write something that looks like a WebApp that runs everywhere. There are technologies such as Cordova, Titanium, and others based on WORA. They are all based on the lowest common denominator and can be extendable with plugins to support platform specific features such as NFC or Force Touch, and others.

We generally cannot take full advantage of the features offered by each platform.

Platform-specific features are mostly related to the capabilities of the OS installed and the hardware available in the device. They impact the overall user experience.

From Mono to Xamarin

Mono is an open source implementation of the Microsoft .NET Framework based on the Common Language Runtime (CLR).

It was initially released in 2004 after three years of open source development launched by a small team of people that included the current founder and CEO of Xamarin, Miguel De Icaza.

Note

Xamarin is derived from Mono framework, which is a cross-platform implementation of .Net Runtime. Xamarin was acquired by Microsoft and open sourced all Xamarin frameworks in February 2016. Microsoft also open sourced .Net Framework and made a cross-platform implementation of it, called .Net Core Framework.

MonoTouch was initially released in 2009 and in 2013 its name became Xamarin.iOS.

Xamarin.iOS is a set of libraries (.dll files) that bind the native iOS SDK.

The iOS binding is the way Xamarin maps the idioms used in Objective-C to the idioms used in .NET.

Mono for Android was initially released in 2011 and in 2013 its name became Xamarin.Android. It is a set of libraries that bind the native Android SDK APIs.

The Android binding maps the idioms used in Java to the idioms used in .NET.

Xamarin.iOS and Xamarin.Android are extendable.

A binding project can be written in order to wrap libraries written in Java or Objective-C into a dll that can be used from our C# projects.

Each single feature of the operating system, third-party libraries, and even our own native libraries can be ported writing a binding project.

The architecture of Xamarin allows us to use the best that iOS SDK can offer to iOS based-devices and the best that Android SDK can offer to Android-based devices.

Xamarin adds another value from the developers' point of view: it allows us to use most of the features of the .NET Framework while developing for Android and iOS devices.

From Xamarin to native

Xamarin.iOS based C# code is compiled using ahead-of-time (AOT) compilation. The resulting compilation output produces a single statically compiled ARM binary.

AOT compilation pre-generates all the native code that the Just in Time (JIT) compiler would normally generate from the Intermediate Language (IL). IL is stripped from the managed assemblies, leaving only metadata. AOT links the metadata together with the JIT-less runtime into a single native binary that can be signed with the Apple account.

Note

An Apple Developer account is needed in order to publish the application to the App Store for iOS devices.

For more information, visit https://developer.apple.com .

The Xamarin.Android application runs within the Mono execution environment (also known as Mono Virtual Machine). The Mono Virtual Machine runs side-by-side with the Dalvik Virtual Machine. Dalvik is an integral part of the Android software stack. It is a process virtual machine in the Android operating system that executes applications written for Android.

The connections between the two virtual machines are created by two Java Native Interface (JNI) bridges:

  • Android callable wrappers: These are used any time the Android runtime needs to invoke managed code

  • Managed callable wrappers: These are used any time the managed code needs to invoke Android code

The managed callable wrappers are generated via .jar binding and are responsible for converting between managed and Android types.

Xamarin cross-platform

With Xamarin we have different ways to share code.

In general, we want to create a platform specific app writing the most common code we can.

As we can see in the following image, Xamarin.Forms provides shared app logic and shared UI code across platforms. With that support, we can easily develop one true application running and displaying the same on all the platforms.

But there is a thin layer on top of shared layers, and that thin layer adds platform-specific customizations to the Xamarin.Forms projects:

The ways to share the common code are:

  • Portable Class Libraries

  • Shared Projects

Shared Projects work in a similar way to file linking. All the files contained in a Shared Project are conceptually copied into each referencing project and compiled as part of them.

Portable Class Libraries (PCL) allow us to produce libraries that can be shared across multiple platforms including Xamarin.iOS, Xamarin.Android, and Windows Phone.

When we develop a PCL, we can reference and use it in each platform specific project.

Xamarin.Forms is a UI Toolkit that allows us to share most of the UI components across platforms. Xamarin.Forms has been implemented as a .NET PCL.

What do we need to start?

To develop iOS Apps, we need a Mac in order to compile and run the code.

Xamarin and Microsoft both provide us with very useful and productive IDEs. Microsoft offers a state of the art IDE, Visual Studio, and its free edition Visual Studio Community to us to create cross-platform applications.

Xamarin offers the free Xamarin Studio to us to create cross-platform applications.

Microsoft's Visual Studio runs on Windows, while Xamarin's Xamarin Studio runs on Windows, Linux, and Mac OS.

We also need an App Store account that allows us to download the iOS SDK and Xcode. To develop iOS applications using C#, we need to download and install onto our Mac both Xamarin Studio and Xamarin.iOS.

We will learn more about Xamarin Studio later in this chapter.

To develop Android apps, we need to install the Android SDK.

We can access the Android SDK Manager directly from Xamarin Studio as well as Visual Studio.

To develop Android apps, we need either a Mac or a Windows machine with Xamarin Studio or Visual Studio with the Xamarin.Android plugin.

 

Xamarin Studio


Xamarin Studio is an IDE from Xamarin. We can download it from http://xamarin.com/download .

Xamarin offers different options in its store. To check the version and the plan we need, we can visit http://store.xamarin.com .

The editor

The following screenshot shows Xamarin Studio on Mac OS:

Xamarin Studio could change design in the future, but currently, when we start Xamarin for the first time, we are presented with three areas. Our most recent projects opened are presented on the left. The news from the Xamarin blog is presented in the central area. A list of examples is presented on the right side and we can download, explore, and run them on our devices.

At the top of the left panel are presented the buttons to create a new solution or open an existing one.

A solution is a container for the collection of projects we need to write in order to develop our apps. We will explore in the next chapter all the details of the available project types we can create with Xamarin.

Our focus is now on what Xamarin Studio offers and how we can use this editor in order to work more quickly and more efficiently, taking advantage of all its features.

We can now start developing our first solution:

  1. Click on the File | New | Solution.

  2. On the left side list, select Android | App.

  3. Click on Next.

  4. Write XamarinByExample in the empty field called App Name.

  5. Click on Next:

  6. Check summary page and click on Create:

The Xamarin Studio template automatically adds the following to the project:

  • References to the libraries Mono.Android, System, System.Core, and System.Xml.

  • The Resources folder with all the base resources the simple app needs

  • A file named MainActivity.cs that is the main point of access to the app

  • The Assets folder

  • The Properties folder

More libraries can be referenced manually by double clicking the References folder on the Solution pad.

Adding an iOS project allows us to see one initial difference:

  1. Right-click on the Solution.

  2. Select Add | New Project.

  3. In the left side list, select iOS | App. In the central list, select Single View App.

  4. Write XamarinByExample.iOS in the empty field called App Name.

The Xamarin Studio template creates for us a new iOS project with a simple Hello world app.

It automatically adds the following to the project:

  • The references to the libraries Xamarin.iOS, System, System.Core, and System.Xml

  • The Resources folder

  • AppDelegate.cs: The class responsible for launching the UI of application, as well as listening (and optionally responding) to application events from iOS

  • Entitlements.plist: The file that configures the permissions on iOS

  • Info.plist: The file that configures the entire app

  • Main.cs: The entry point of the application

  • MainStoryboard.storyboard: The file with the UI storyboard

  • XamarinByExample.iOSViewController.cs: This is the ViewController that manages the page designed in the storyboard

Right now we are going to focus on the editor:

The first button in the top bar is the Run button. When we click it, our app runs with the Configuration (Debug, Release) selected in the combo named Configuration selector.

We can select where to run our app using the target selector. The target selector is a combo that contains the list of available devices. They may be either real devices plugged to our machine or virtual devices configured to run in a simulator.

On the top in the center we have the Notification Area. Here we can be notified about the numbers of warnings or errors in our app, or the results in a search.

When we click on the Notification Area, Xamarin opens up the associated details pad to show us more details of the selected notification.

In the top right section, we find the Global Search field.

This is a very useful feature of Xamarin, and we are going to explore it in more detail.

The left-hand section is called the Solution pad, and it contains all the files in our solution.

The central section contains the Document. When we open a file from the Solution pad, it gets displayed, if possible, in this section.

Tip

To zoom in and out the content, use the short keys Ctrl  + or Ctrl  - in Windows and command  + or command  - in Mac.

The right-hand section contains the properties and hidden pads that we can customize.

Tip

To hide a panel, double-click on its title.

We can customize most of what we've seen so far.

The global search

The global search is one of the most powerful features of the editor.

It allows us to easily jump to the point of the code we need to retrieve.

Go to is the main feature of the global search, and this allows us to find a type, a file, or a declaration.

All we need to write is type:NameOfTheTypeWeAreLookingFor and we will be directed to the type.

Tip

Using the global search, we can write in the filter just the uppercase letter of the object in camel case we are looking for. So for example, if we are looking for the file MainActivity.cs, we can just write file:MA and the file will appear on the list eventually with all the others compliant with our filter.

When we are in a file, we can jump to a known line by typing in the global search :NumberOfLine:NumberOfColumn.

For example, :10:10 jumps to the 10th line and 10th column of the document.

The key bindings

The key bindings is a feature that allows us to use short key combinations for actions.

In the following table, we can have a look at some of them:

Short key

Description

⌘+ D

This generates the constructor of the class.

cw

Console.Writeline.

switch

Template for the switch statement.

exception

Template for an entire class exception.

prop

Template for a short property.

If we need a private set, we can use propg.

try

Template for try...catch.

In the menu Tools | Options (Windows) or Xamarin Studio | Preferences (Mac), in the section Environment | Key Bindings we can look at all the default short keys and we can also define ours.

Policies

Xamarin Studio allows us to customize how the code will be automatically formatted.

We will find this feature very useful when we want to be consistent with the coding standard of our company or the coding standards of our customer.

To customize it, we go to Tools | Options (Windows) or Xamarin Studio | Preferences (Mac) and select in the left menu Source Code | Code Formatting | C#. A drop-down list appears, where we can select the coding style we prefer, or we can also define our own coding standard by going in to the tab C# Format. We will now see an example of code with the current coding standard. Clicking on the Edit button, we can choose from different layout options for Indentation, Braces, Blank Lines, Wrapping, White Spaces, and New Lines.

The Code Formatting settings are not saved in the solution but in the local settings of Xamarin Studio. If we share our code with another person with different policies, when they open the solution with their customized Xamarin Studio, they will have the option to apply their own policies for the solution or use the project specific user settings.

Tip

We can apply our policies to the document with the short key Ctrl + I.

Code template

A code template is a block of reusable code that we can insert where we need it in our code. Code templates can be simple or very complex. For example, blocks such as try…finally and if…else are commonly used, but we could also use code templates to insert entire classes or methods.

To try one of them, we can go to the Program.cs, writing in the global search file:Program.cs and pressing Enter.

Tip

Ctrl + Shift + D (Windows) or command + shift + D (Mac) automatically writes file: in the global search and moves the focus there.

After the Console.Writeline("Hello World"); we can write for and press double Tab.

There the following code would automatically appear:

for (int i = 0; i < max; i++) 
{ 
 
} 

Using the Tab button, we can navigate between two fields, i and max. We can change them with the values we need. By replacing the field i with myIndex, all the i in the template will be updated with the new value. When we arrive at the last editable value, we can press enter and at this point the template will be transformed in to regular code.

The code templates are written with a simple meta-language.

Here is a small list of the code templates we can find useful:

Keyword

Code template

ctor

It generates the constructor of the class.

cw

Console.WriteLine.

switch

Template for the switch statement.

exception

Template for an entire class Exception.

prop

Template for a short property.

If we need a private set we can use propg.

try

Template for try...catch.

As an exercise, we can try all of them in our code. To use them in our code, we need to write the keyword and press double Tab.

There are about 40 templates currently available for C# in Xamarin.

Going to Tools | Options (Windows) or Xamarin Studio | Preferences (Mac), under the Text Editor section we can find Code Templates, with all of them, and details of how they are implemented.

We can also write our own code template.

If we try to add a property by writing in the code prop + double Tab, it generates a short property as follows:

public object MyProperty { 
            get; 
            set; 
        } 

This has object and MyProperty as editable.

The implementation of this template in the meta-language is relatively easy.

public $type$ $name$ { 
    get; 
    set; 
} 

The words between the symbol $ are the ones that are editable. We can put them  in the code more than once, and when they have different names they can be navigated with the tab button. When they have the same name, the engine repeats for us, in realtime, what we write in the first field with that name.

It would be great and always useful to have a template that writes an extended property like this:

private object _myProperty;
public object MyProperty{
  get
  {
    return _myProperty;
  }
  set
  {
    _myProperty = value;
  }
}

Unfortunately, there is not a code template like this. The bright side is that we can create it.

Go to Tools | Options (Windows) or Xamarin Studio | Preferences (Mac), select Code Templates from the Text Editor section, and press Add.

As a shortcut, we can write propex. We need to select C# from the drop-down list called group and text/x-csharp from the drop-down list called mime. As a description, we can write Template for extended properties.

private $type$ $name$; 
public $type$ $Name${ 
    get 
    { 
        return $name$; 
    } 
    set 
    { 
        $name$ = value; 
    } 
} 

Now in the drop-down list, on the right, we can select three new fields that are all the fields we inserted between the $ symbols.

We can define the default values for type, name, and Name.

After defining the default values for each field, we just need to press OK to save the snippet.

Source analysis

This is a very useful feature of Xamarin, disabled by default. When we enable it we have a powerful tool to raise the level of quality of our code.

The source analysis checks code on the fly and warns of potential errors and style violation, suggesting automatic fixes. To enable it, we need to go to Tools | Options (Windows) or Xamarin Studio | Preferences (Mac) and turn it on from the Text Analysis in the Text Editor section.

When enabled, we can see markers in the scroll bar. By moving the mouse over them we can see the problems colored by severity. The scroll bar gives us a high level view of the quality of our code. Some of the suggestions are just recommendations, and this doesn't mean that they have to be addressed.

If we click on the marker and press Alt + Enter, a list of suggested actions will be shown and we can decide whether or not to automatically fix the issue with the suggested action.

Regions and comments

Regions let us specify a block of code that we can retrieve in the navigation bar at the top left side of our document. In longer code files, it is convenient to separate the code into regions so that we can focus on the part of the file that we are currently working on. The following example shows how to define a region:

#region MyClass definition public class 
MyClass 
{ 
 static void Main() 
 { 
 } 
} 
#endregion 

A #region block must be terminated with a #endregion directive.

Tip

To write a region using code template, we can type #region and double tab.

In general, we can comment a line in C# by using // before the part to comment or /* before the first char to comment and */ after the last one. In Xamarin Studio, we can also use a particular comment in our code by using // TODO: our comment. This will add the line commented on a task list that we will retrieve any time by clicking on the button Tasks positioned at the bottom right of Xamarin Studio.

To comment our classes and fields we use the documentation tags.

The documentation tags are comments in XML that can be useful if we want to automate the technical documentation of our app. The documentation tags are defined using /// and XML markup.

Xamarin generates the documentation tags for us. The quality of the auto-generated documentation tags is related to the quality of the coding standards we use.

Let's add, for example, a method to Program.cs called TransformTextInLowercase that transforms a string in its lowercase:

string TransformTextInLowercase(string textToTransform) 
{ 
     return textToTransform.ToLower(); 
} 

Adding the /// in the row before the first one and pressing enter allows Xamarin Studio to generate the following comment for us:

/// <summary> 
/// Transforms the text in lowercase. 
/// </summary> 
/// <returns>The text in lowercase.</returns> 
/// <param name="textToTransform">Text to transform.</param> 
string TransformTextInLowercase ( string textToTransform) 
{ 
      return textToTransform.ToLower(); 
} 

Xamarin and the Microsoft C# compiler provide us with a way to extract the documentation from the comments.

It looks for XML documentation comments within the source code (comments that start with three slashes, ///), and puts them all into a single XML file.

To auto generate this XML file, we have to:

  • Double-click on the name of the project in the solution pad. This opens the properties of the project.

  • Click on Compiler under the Build section on the left side list.

  • Flag Generate xml documentation.

  • Choose a folder and a filename.

  • Press the OK button.

Next time we compile, a new XML file that contains all the documentation tags will be automatically generated in the deployment folder.

The xml file can be used as the starting point to generate automatic documentation. We can write an xsl to present the data in html, or use tools such as NDoc, Monodoc, or Sandcastle to build a help file.

 

Mobile Development Software Development Lifecycle


A Mobile Development Software Development Lifecycle (SDLC) is composed of distinct work phases used to plan, design, build, test, and deliver a mobile app.

An SDLC aims to produce high quality apps that meet or exceed our customer expectations.

We need to base our apps on customer requirements. To do that, it helps to move through clearly defined phases, and prepare scheduled time-frames and accurate cost estimates:

Usually there are six major phases:

  • Idea: All apps start with an idea. That idea is usually refined throughout the entire SDLC process.

  • Design: In this phase we define the general layout and how it works. It usually starts by defining the User Experience (UX), converted into a UI design.

  • Development: This phase is the most intensive for us. In this phase we build the application.

  • Testing: When the development phase is far enough along, we can release a test application to the QA or test users. This allows us to address possible issues that our app might contain. Testing early is good for our products. Some software development methodologies are driven by testing, or include feature based testing as soon as a feature is available.

  • Deployment: This releases the app to the stores, or in some of the preview environments available.

  • Feedback: In this phase, we collect opinions on the app, and based on them, start the process again. This is an important and often under evaluated phase. Listening to our final users is always more important than the technology we use.

These phases often overlap. For example, it is common to start development before the design is finished, or start testing before the development is at a good point but not completed yet.

Idea

Ideas are cheap! Execution is worth millions! Walking on the streets of San Francisco, you will hear that many times. It is actually pretty true. Ideas are cheap.

Potentially everyone has a brilliant idea for the next killer app!

Defining an idea is a key phase in creating a successful app. It is only a small step compared to the execution but it is an important step. Having a clear idea helps us to have clarity from the beginning about what we need to do to transform the idea into reality.

It is all about asking and replying to fundamental questions driven by the market.

To define an idea, we can create our own template in order to have the big picture of the overall app.

In the following table, I am including questions I usually need in order to understand what I am going to develop and why.

We can copy, fill, and pin it in front of us in order to not lose focus during all the phases of the SDLC:

Question

Answer

Are there similar apps?

If so, how does the idea of the application differentiate from the others?

Will the application integrate with or extend the existing infrastructure?

If so, what kind of infrastructure needs to be extended or integrated by the app?

 

What value does this app bring to users?

How can I add value using mobile technologies such as location awareness, the camera, and so on?

This table can obviously grow. The experience will always suggest new questions to us.

An idea sets one or more goals.

When we have the list of goals, we can think about all the steps the user needs to take in order to achieve each one of them. The user is called the Actor. Sometime an actor can be another system connected to our app.

The steps the Actor needs to take to achieve a goal are called the usecase.

Defining Actors and usecases tells us what the requirement specifications are.

After that, we can focus on how to design a technical solution that covers the requirement specifications.

Design

When we know what is needed, we can start to think about UX and UI.

User experience design

The UX design is the process of maximizing the usability and the interaction between the user and the application.

This is usually done using mockups and wireframes that may be created even with low tech tools: pencil and paper. But don't worry, that is not the only way! There are tools such as Balsamiq and InVisio that help UX designers to define mockups, providing a first feeling of the app.

This helps to define the interactions and the placeholders before starting the UI design.

User experience is not cross-platform.

When designing the user experience, it is important to consider the interface guidelines for each of the platforms we are designing for.

By following the platform-specific guidelines, we can ensure that our apps are well integrated on the operating system where they are running:

For example, each platform has its own way to switch between sections, to manage images, and so on. Even the available hardware influences the user expectations for our app. For example, Android devices have a back button, while iOS users expect to have a button in the UI that drives them back to the previous section and the only button is expected to go to the main screen.

User Interface design

UI design transforms the mockups into graphics elements. Spending time on a good UI design is always a good investment. Consider that the most popular apps generally also have great designs and usability.

A well-designed app usually looks different on each platform. As for the UX, it's important to understand that each platform has its own design language.

One example of these differences is the dimension of icons and images that we need in order to see them sharply and crisply on each supported platform.

Development

Development often starts with a proof of concept that validates functionality.

The rest of the book will focus on this phase.

Testing

This is the process of finding and working out the bugs in our app.

Testing generally includes usability and design reviews.

This phase is the overall test of the app, and generally the application follows different stages:

  • Proof of Concept: Only the core functionality is working and major bugs are present.

  • Alpha: Core functionality is code-complete and not fully tested. Major bugs are still present and some features may still not be available.

  • Beta: Most of the functionality is complete. Known issues are present. The app has had some testing and bug fixing.

  • Release candidate: All functionality is complete and tested. The app is ready to be published.

Xamarin provides a powerful testing framework called Xamarin Test Cloud. This allows us to write automated UI testing.

During development, we can write small tests to check single functionalities (unit testing). We will experience how to develop testing with C# and NUnit later in the book.

In general, the sooner the app is tested, the earlier we can address the issues. For example, if a major issue is found in the proof of concept, the UX of the app can be still modified to address it.

There are different tools to support the distribution in the test phase:

Xamarin Insights (https://xamarin.com/insights) is a technology presented in 2014 and designed to bring analytics and crash reporting to our mobile app. It is a real-time monitoring system that enables us to identify, report, and track issues that are impacting users with a simple and effective API.

We will explore the features of Xamarin Insight later in the book.

Deployment

Once our application is stable enough, we can publish it. The deployment is a platform specific step. The distribution options depend on the platform. We will explore an example of deployment in the last chapter of this book. For now, we will have a quick overview of the options.

Distributing through Apple Connect

Apple iOS apps are distributed to the Apple "App Store" via "Apple Connect".

When we submit an App to Apple Connect, we have to wait for a validation. Usually Apple is very strict with the validation process and it can take some weeks.

If our app is not compliant with all the Apple guidelines, it will be rejected with a list of issues to address in order to be compliant.

The Apple Store is the most popular distribution method for iOS applications, and it allows us to market and distribute our apps online with very little effort.

The second type of deployment is the enterprise deployment.

This is used for internal distribution of corporate applications that aren't available via the App Store.

A deployment also exists that is intended primarily for development and testing: "ad-hoc deployment".

Note

When we deploy to a device via Xcode or Xamarin Studio, it is known as ad-hoc deployment.

Distributing through Google Play

The official app store for Android is Google Play, but as we will see, there are a few other different stores that we can consider.

Android is also open to app distribution. Devices are not locked to a single, approved app store.

Anyone is free to create an app store, and most Android phones allow apps to be installed from these third-party stores.

This allows us a potentially larger distribution channel for our applications.

Distributing through Windows Store

Windows Phone applications are distributed to users via the Windows Store.

We need to submit our apps to the Windows Phone Dev Center for approval, after which they appear in the Store. When we submit our apps to the Windows Store, we can also provide an install link to the testers before the app is reviewed and published.

Feedback

During the development cycle we need to collect feedback from the test users.

At this stage we might have usability reviews and functionality reviews.

We will understand our customer better, and what is needed to add value to our app.

 

Summary


In this chapter, we've started our journey towards learning what mobile cross-platform means, and how to start using Xamarin Studio and its features in order to write our apps with C#.

We prepared all the basics and tools we need to make our first app.

We overviewed the Software Development Lifecycle for mobile applications.

Now we are ready to start developing with Xamarin Studio.

In cross-platform projects, sharing code between projects is important and there are ways to achieve this goal. We'll examine the aspects and methodologies of sharing code by shared projects in next chapter.

Separation between the UI and code behind it is also important. We'll address the MVVM design pattern and learn it by writing an example library.

About the Authors
Latest Reviews (1 reviews total)
Fácil y rápido, siempre es una experiencia muy buena
Xamarin 4 By Example
Unlock this book and the full library FREE for 7 days
Start now