Mobile computing is here. We cannot ignore the fact that more mobile computing devices sell than the classic PCs and hence mobile developers need to understand how to leverage the benefits of cloud computing for their mobile applications.
Basics of Windows Azure Mobile Services
To help developers easily offer the power of cloud computing to their mobile applications, Microsoft offers “Windows Azure Mobile Services”, which allows creation of a scalable and secure backend for mobile applications. Windows Azure Mobile Services provides structured storage, user authentication and the ability to send push notifications.
Mobile Services enable application developers to:
1. Store Data in the cloud
2. Authenticate users easily
3. Easily send push notification
4. Easy customization to enable use of selected services
5. Support for monitoring, alerting and auto scaling
To see how easy it is to use Windows Azure Mobile services, let’s create a simple Android application powered by these cloud services.
First, we will use the Windows Azure Management portal to create a new mobile service.
One of the pre-requisites of the hands on exercise is a Windows Azure subscription. A free trial is available by visiting http://www.windowsazure.com and clicking Free Trial.
Once signed up, login to your Windows Azure subscription at https://manage.windowsazure.com
You will see the screen below.
Log into Your Windows Azure Subscription
Click the “New” link at the bottom of the page, choose “Computer > Mobile Service” and then “Create”, as shown below.
Create Mobile Service
Provide a name for the URL for your mobile service. In our case, I am naming the URL testAndroidApp. The complete URL will be testAndroidApp.azure-mobile.net.
Leave the default setting for the database (which should be “Create a new 20 MB SQL database”. Choose the other options as it maps for your use case. For the purpose of the demo, I am leaving it to the default values.
Create a Mobile Service
Click the next arrow.
You will now see the database settings. Select a new SQL database server and provide the server login name, login password and the region you want the server to be in.
Click the Complete link. This will start the creation of a new mobile service.
New Mobile Service
In a few moments, the new mobile service will be ready.
The next step involves creating a new Android application. Microsoft has made it easy to create a new Android application, by providing short cut steps in the Windows Azure Management Portal itself.
Once the new mobile service is ready, click the service name or the arrow next to its name as shown below.
Click the Arrow
This will take you to the Dashboard page for the mobile service.
Now, we will provide the platform for which we want to build an application. Click Android as shown below.
The links below will change to show “Create a new android app” and “Connect an existing Android App”.
Create a New Android App or Connect an existing Android App
For our case, we will choose “Create a new Android App”. The page will now show additional information as shown below.
Create a New Android App
At this time, if you do not have the Android Developer Tools, you need to install them. They are available from https://go.microsoft.com/fwLink/?LinkID=280125&clcid=0x409
We will now click the link to “Create TodoItem Table”.
A test table, which we will be using in our Android application, will be created for us.
Create a Table
Next, we will download the starter Android project by clicking the Download link.
Once downloaded, extract the contexts of the zip file to your local folders.
Now, fire up Eclipse and choose File->Import. When the Import dialog is presented, choose “Android -> Existing Android Code into Workspace” and click “Next”.
At the next screen, provide the path to the folder where you extracted the zipfile and click Finish.
The downloaded project will now be imported into your Eclipse workspace.
Some of you might get an error shown below.
[2014-02-23 15:14:45 - testAndroidApp] Unable to resolve target 'android-18'
If you get the error, launch Android SDK manager, and download Android 4.3 (API 18).
Android SDK Manager
Once your project is successfully loaded in Eclipse, you can execute the application by clicking Run.
Once the application runs, it will be rendered as below.
At the moment, the application only adds items in a todolist (the default template for the Windows Azure Mobile services application).
If you enter any text and click “Add”, the content will be added to the cloud based database.
You can verify that the data is stored in the cloud by navigating to the Data section of the testAndriodApp workspace on the Windows Azure Management portal (as shown below).
Data section of the testAndriodApp Workspace
Click the TodoItem table name.
The TodoItem Table
You can see that the detail you provided for the task is shown under the text column.
We can see how simple it was to create an Android application powered by Windows Azure Mobile Services.
To see what is under the hood, check out the default source code that was created by the wizard. You can customize this code to make this work for the application you want to build.
In this article, we learned how easy it was to create Android mobile applications powered by Windows Azure Mobile Services. I hope you have found this information useful.
About the Author
Vipul Patel is a Program Manager currently working at Amazon Corporation. He has formerly worked at Microsoft in the Lync team and in the .NET team (in the Base Class libraries and the Debugging and Profiling team). He can be reached at email@example.com