Data Synchronization with Android

Max Pettit
Data Weekly by Jumpmind
3 min readFeb 7, 2018

Overview

With the continuous advancement of mobile processing power, mobile applications have become increasingly popular. Whether a mobile application is intended for business or personal use, there is almost always a need for data persistence or remote data storage. Integrating databases into mobile applications can be challenging because options and functionality are much more limited than non-mobile platforms. SymmetricDS provides an alternative to typical mobile database solutions that provides more flexibility and features.

SymmetricDS is an open source database replication tool that is highly scalable and configurable. SymmetricDS supports a wide variety of database platforms such as MySQL, Microsoft SQL Server, PostgreSQL, SQLite, Oracle, and more.

SymmetricDS includes Android libraries that allow for easy integration into Android applications. These libraries can provide data synchronization with existing database servers or even other Android devices.

How it Works

SymmetricDS takes advantage of native SQLite support on Android devices. Data is stored locally on the device in a SQLite database which can then be synchronized with other remote databases. When data is created or modified on each database, it can be captured by SymmetricDS. The changes can then be sent to other databases so that the data is persisted across devices. See the SymmetricDS documentation and How To articles for more details about how SymmetricDS synchronizes data.

Getting Started

JumpMind, Inc. has now published a sample Android application that can be used to demonstrate the basic functionality and integration process. The sample application can be found in the JumpMind GitHub repository.

This project was created using Android Studio 3.0.1 , Android SDK 26, Java 8, and SymmetricDS 3.9. Android Studio is the official Android IDE for developing Android applications using Java.

Setup the Demo Configuration

Download the latest symmetric-server installation.

The demo Android application is designed to work with the demo configuration used in the Quick-Start tutorial.

Follow along the Quick-Start demo instructions to setup an example configuration on your local machine. This will create a configuration with a sample corporate database and two store databases. These databases are configured to synchronize sample tables called ITEM, ITEM_SELLING_PRICE, SALE_TRANSACTION, and SALE_RETURN_LINE_ITEM.

After completing the Quick-Start demo configuration instructions, stop SymmetricDS, update the engines/corp-000.properties file and update the sync.url property to replace localhost with your local machine’s IP address.

Setup the Demo Android Application

Once the demo configuration is up and running, the Android application can be setup to synchronize data with your local machine. The demo application will act as a store database to sync tables to the corporate databases.

Download the SymmetricDS Android libraries. Extract the libs directory and copy the entire directory to the app/libs directory in the Android project.

Next you will need to modify the DbProvider class in the Android project code. Update the REGISTRATION_URL String to be the same as the sync.url on the corp-000 node after it was modified in the section above.

Now you are ready to deploy the application to an Android device or emulator.

Running the Demo Android Application

When the application is started, it will attempt to register the new Android node with the registration URL used above. In order for the registration process to complete, you must allow registration on the corp-000 node. To do this run the following command on your local machine:

bin/symadmin open-registration --engine corp-000 store android-003

Now you can deploy the Android application and the new node will register with the corporate node.

The demo application includes a text entry window that allows you to directly query the local SQLite database and display the output below. You can also use the other buttons to quickly generate queries for testing synchronization.

You can test by using the SALE_TRANSACTION insert query on the Android device and observing the table on the corp-000 database. You can also insert into the ITEM table on the corp-000 database and observe the table on the Android device.

From here, follow along the SymmetricDS documentation to configure your own nodes and tables for synchronization.

--

--