App state persistence
Collapse the table of content
Expand the table of content

App state persistence programming overview (Android versus Windows Store apps)

[This article is for Windows 8.x and Windows Phone 8.x developers writing Windows Runtime apps. If you’re developing for Windows 10, see the latest documentation]

Learn about key similarities and differences between app state persistence programming models for Android and Windows Store apps.

Introduction

Getting and changing app data on a server is a common need if the data needs to be shared with other devices or users, or if it requires some kind of server-side processing. Examples include game leaderboards, e-commerce, newsreading, microblogging, and social networking apps.

Top

Custom state management

Both Android and Windows Store apps can use their respective HTTP client APIs (for example HttpClient and HttpUrlConnection for Android and HttpClient and Windows Communications Foundation (WCF) proxies for Windows Store apps) to connect to custom web services hosted in the cloud or in one's own infrastructure, if available. The developer can use server-side technologies such as ASP.NET, Java, Java API for XML Web Services (JAX-WS), and PHP for building hosted web services on Windows and Linux.

Various open source frameworks and Microsoft .NET accelerate the creation of web services for Android and Windows through server-side programming models on the client. Developers must find separate infrastructure to host these web services, manage the infrastructure, and monitor for web service availability and scalability.

Top

State management through pre-built cloud services

Both Android and Windows can work with industry-standard web services. To speed up the development and deployment of web services on the server, several service providers offer pre-built web services for app state management and push notifications. Microsoft also offers Microsoft Azure Mobile Services (WAMS) for saving app data through simple API calls. WAMS is hosted on Microsoft Azure and simplifies server-side web service creation, hosting, and operations through a managed web services infrastructure.

Typically, a developer configures a WAMS web service and then plugs in JavaScript code for typical server-side create, read, update, and delete calls on certain data entities. Android and Windows Store apps can use WAMS.

Following is a WAMS pseudocode snippet example for an Android app.


public class Customer {
    @com.google.gson.annotations.SerializedName("name")
    private String Name;
    @com.google.gson.annotations.SerializedName("city")
    private String City;
}

public class Activity1 extends Activity {
    private void testWAMS() {
        MobileServiceClient mobileClient = new MobileServiceClient(WAMS_URL, this);
        MobileServiceTable<Customer> customerTable = mobileClient.getTable(Customer.class);

        // Create a customer record. 
        Customer customer = new Customer("John","Seattle"); 
        customerTable.Insert(customer, callback);

        // Update a customer record.
        customer.setCity("Houston");
        customerTable.Update(customer, callback);

        // Read a list of customer records.
        customerTable.execute(callback);
    }

    // Code not relevant to the discussion omitted for brevity.
}

Here's a similar C# pseudocode snippet example for a Windows Store app.


public class Customer 
{
    public string Name { get; set; }
    public string City { get; set; }
}

public partial class MainPage: Page
{
    private testWAMS()
    {  
        MobileServicesClient msc = new MobileServicesClient(WAMS_URL);
        IMobileServiceTable<Customer> customerTable = 
            App.MobileService.GetTable<Customer>();

        // Create a customer record. 
        Customer customer = new Customer{Name="John",City="Seattle"}; 
        await customerTable.InsertAsync(customer);

        // Update a customer record.
        customer.City = "Houston";
        await customerTable.UpdateAsync(customer);
     
        // Read a list of customer records.
        MobileServiceCollectionView<Customer> customers = 
            customerTable.ToCollectionView();
    }
    
    // Code not relevant to the discussion omitted for brevity.
}


For more info, see Microsoft Azure Mobile Services.

Top

 

 

Show:
© 2017 Microsoft