This past week I decided to write an android app with Xamarin and launch it on the Google Playstore.  My app is a simple concept which currently doesn’t exist out there, that is paying your mortgage from your smart phone.  I named my app “Mortgage Pay”, and for phase 1, I decided to do a prelaunch to test out the app writing process on Xamarin.  The architecture of my app is as follows:

 

  • Web Services written in ASP.NET Web-API 2
  • SQL Server 2014 database
  • Xamarin, using C# for the front end

 

 

To get started with xamarin, you have to download the Xamarin platform to integrate with Visual Studio.  I am currently using Visual Studio 2015, and went here to download Xamarin:

https://www.xamarin.com/download

 

Once I get that installed and setup, the android emulator came with it and I was ready to start developing my app.  I decided to write a native app, and not use phonegap or cordova.  Once you have Xamarin installed, when you go and create a new project, it will give you the option as the following:

 

Once you create your project, then you’re pretty much ready to go.  It’s very similar to eclipse, where the folder structure contains your C# code, and the layouts, colors, styles to edit using xml and xaml, which is the default interface layout file for an application.  The layout syntax is almost exactly the same as the eclipse version for android layouts, and it wasn’t hard for me to pick up where I left off. I was able to use the LinearLayout, TextView, EditText tags to construct my layout:

 

Very similar to the android layout in eclipse.  There is even a designer to use in Visual Studio, but I didn’t partake in using it, as I thought using the XML tags easier to format and view.  The one downside also was running the app, it took an average of 15 – 30 seconds to have it loaded on the android emulator.  Once you start the android emulator, you shouldn’t close it, or else it will take too long to restart the emulator again.  I just kept the emulator open and debugged the application inside Visual Studio. Stopping the debugger in Visual Studio, doesn’t stop the emulator, so you can restart and start your app to test it.

 

 

Web API makes it so easy to use their registration process, as I used ASP.NET Identity.  I needed to add an additional field, and it was a breeze.  The android concept of Activities is still alive, and an Activity basically acts as a form where you can place different objects such as text fields, buttons, labels, and add events to them.  The Resources folder is very important as that contains your layout rules, for colors, styles and images for your app.

 

As you know also, C# makes it very easy to call web services, so HttpClient to post an Async call, for a response.   It’s as easy as a few lines of code:

 

ProgressDialog progressDialog;

 

progressDialog = ProgressDialog.Show(this, “”, “Please Wait…”, false);

progressDialog.SetProgressStyle(ProgressDialogStyle.Spinner);

 

var formContent = new FormUrlEncodedContent(new[]

{

new KeyValuePair<string, string>(“Email”, payer.Email),

new KeyValuePair<string, string>(“MortgageCompanyName”, payer.MortgageCompanyName)

});

 

var myHttpClient = new HttpClient();

var response = await myHttpClient.PostAsync(URL, formContent);

 

var json = await response.Content.ReadAsStringAsync();

 

The ProcessDialog is what I used to have the spinner while we wait for the response from my web service.

There were really no growing pains in writing this app, and found the process very easy to do. To be honest, the beauty of writing apps vs a full blown web application is that you really need only minimal functionality.  As long as you understand the following:

  1. Control Events
  2. MVC
  3. Web service calls
  4. AXML Layouts

Not to simplify it, but that’s all there is in my opinion.  Perhaps I am being naïve, but if we really break it up into small pieces, as a developer, it shouldn’t have to be too complicated.  I found learning the layout was a little bit of a learning curve, but as I started doing it, I started to get it. It really wasn’t the fault of Xamarin, just something you need to understand to stay within the MVC architecture.  The AXML Layouts are like your views, and can be plugged into any activity.

Of course Phase 1 of my app isn’t as robust as I wanted it to be, but I didn’t want to get stuck in analysis paralysis, and see how easy it was to get started in Xamarin and go from start to finish.

The last part after I set everything up was the deployment. There’s a couple of things you have to change in order to indicate your app is ready for production.  That was very easy as well, but I will cover that in my next post.  If you’re curious, download my app on the playstore for free:

 

https://play.google.com/store/apps/details?id=com.mortpay.app&hl=en

 

Any questions or tips, please let me know, I’m available atparttimeadjunct@gmail.com.

Launched Android App using Xamarin

Leave a Reply

Your email address will not be published. Required fields are marked *