This is an Azure Mobile Services topic. This service has been superseded by Azure App Service Mobile Apps and is scheduled for removal from Azure. We recommend using Azure Mobile Apps for all new mobile backend deployments. Read this announcement to learn more about the pending deprecation of this service.
Learn about migrating your site to Azure App Service.
Get started with Azure Mobile Apps, see the Azure Mobile Apps documentation center.
For the equivalent Mobile Apps version of this topic, see Create an Android app in Azure Mobile Apps.
This tutorial shows you how to add a cloud-based backend service to an Android app using Azure Mobile Services. In this tutorial, you will create both a new mobile service and a simple To do list app that stores app data in the new mobile service.
A screenshot from the completed app is below:
Completing this tutorial requires the Android Developer Tools, which includes the Android Studio integrated development environment, and the latest Android platform. Android 4.2 or a later version is required.
The downloaded quickstart project contains the Azure Mobile Services SDK for Android.
To complete this tutorial, you need an Azure account. If you don't have an account, you can create a free trial account in just a couple of minutes. For details, see Azure Free Trial.
Follow these steps to create a new mobile service.
Log into the Azure classic portal. At the bottom of the navigation pane, click +NEW. Expand Compute and Mobile Service, then click Create.
This displays the Create a Mobile Service dialog.
This displays the Specify database settings page.
As part of this tutorial, you create a new SQL Database instance and server. You can reuse this new database and administer it as you would any other SQL Database instance. If you already have a database in the same region as the new mobile service, you can instead choose Use existing Database and then select that database. The use of a database in a different region is not recommended because of additional bandwidth costs and higher latencies.
In Name, type the name of the new database, then type Login name, which is the administrator login name for the new SQL Database server, type and confirm the password, and click the check button to complete the process.
You have now created a new mobile service that can be used by your mobile apps.
Once you have created your mobile service, you can follow an easy quickstart in the Azure classic portal to either create a new app or modify an existing app to connect to your mobile service.
In this section you will create a new Android app that is connected to your mobile service.
In the Azure classic portal, click Mobile Services, and then click the mobile service that you just created.
In the quickstart tab, click Android under Choose platform and expand Create a new Android app.
This displays the three easy steps to create an Android app connected to your mobile service.
If you haven't already done so, download and install the Android Developer Tools on your local computer or virtual machine.
Click Create TodoItem table to create a table to store app data.
Now download your app by pressing the Download button.
The final stage of this tutorial is to build and run your new app.
Browse to the location where you saved the compressed project files and expand the files on your computer into your Android Studio projects directory.
Open Android Studio. If you are working with a project and it appears, close the project (File => Close Project).
Select Open an existing Android Studio project, browse to the project location, and then click OK. This will load the project and start to sync it with Gradle.
Wait for the Gradle sync activity to complete. If you see a "failed to find target" error, this is because the version used in Android Studio doesn't match that of the sample. The easiest way to fix this is to click the Install missing platform(s) and sync project link in the error message. You might get additional version error messages, and you simply repeat this process until no errors appear.
- There is another way to fix this if you want to run with the "latest and greatest" version of Android. You can update the targetSdkVersion in the build.gradle file in the app directory to match the version already installed on your machine, which you can discover by clicking the SDK Manager icon and seeing what version is listed. Next you press the Sync Project with Gradle Files. You may get an error message for the version of Build Tools, and you fix that the same way.
You can run the app using the emulator, or using an actual device.
To run from a device, connect it to your computer with a USB cable. You must set up the device for development. If you are developing on a Windows machine, you must also download and install a USB driver.
To run using the Android emulator, you must define at least one Android Virtual Device (AVD). Click the AVD Manager icon to create and manage these devices.
From the Run menu, click Run to start the project. and choose a device or emulator from the dialog box that appears.
When the app appears, type meaningful text, such as Complete the tutorial, and then click Add.
This sends a POST request to the new mobile service hosted in Azure. Data from the request is inserted into the TodoItem table. Items stored in the table are returned by the mobile service, and the data is displayed in the list.
Back in the Azure classic portal, click the Data tab and then click the TodoItems table.
This lets you browse the data inserted by the app into the table.
Now that you have completed the quickstart, learn how to perform additional important tasks in Mobile Services: