Menu
AWS Mobile
Developer Guide

Android: Sync Data with Amazon Cognito Sync

New User?

Use AWS AppSync instead. AppSync is a new service for synchronizing application data across devices. Like Cognito Sync, AppSync enables synchronization of a user's own data, such as game state or app preferences. AppSync extends these capabilities by allowing multiple users to synchronize and collaborate in real-time on shared data, such as a virtual meeting space or chatroom.

Start building an Android app with AWS AppSync now.

Overview

Amazon Cognito Sync is an AWS service and client library that enables cross-device syncing of application-related user data. You can use the Amazon Cognito Sync API to synchronize user profile data across devices and across login providers—Amazon, Facebook, Twitter/Digits, Google, and your own custom identity provider.

For instructions on how to integrate Amazon Cognito Sync in your application, see Amazon Cognito Sync Developer Guide.

Set Up the SDK

You must complete all of the instructions on the Android: Setup Options for the SDK page before beginning this tutorial.

Initialize the CognitoSyncManager

Pass your initialized Amazon Cognito credentials provider to the CognitoSyncManager constructor:

CognitoSyncManager client = new CognitoSyncManager( getApplicationContext(), Regions.YOUR_REGION, credentialsProvider);

For more information about Cognito Identity, see cognito-auth-legacy.

Syncing User Data

To sync unauthenticated user data:

  1. Create a dataset and add user data.

  2. Synchronize the dataset with the cloud.

Create a Dataset and Add User Data

Synchronize Dataset with the Cloud

To synchronize a dataset, call its synchronize method:

dataset.synchronize();

All data written to datasets will be stored locally until the dataset is synced. The code in this section assumes you are using an unauthenticated Cognito identity, so when the user data is synced with the cloud it will be stored per device. The device has a device ID associated with it. When the user data is synced to the cloud, it will be associated with that device ID.

To sync user data across devices (using an authenticated identity), see Amazon Cognito Sync.