Домой United States USA — software Building a Kotlin Mobile App with the Salesforce SDK, Part 3: Synchronizing...

Building a Kotlin Mobile App with the Salesforce SDK, Part 3: Synchronizing Data

168
0
ПОДЕЛИТЬСЯ

This post will show you how to synchronize data from your Salesforce org to your mobile device and handle scenarios such as network loss.
Join the DZone community and get the full member experience. This is our final post in our three-part series demonstrating how to use the Salesforce Mobile SDK to build an Android app that works with the Salesforce platform. In our first post, we showed you how to connect to your org. Our second post showed you how to edit and add data to your org from your app. This post will show you how to synchronize data from your Salesforce org to your mobile device and handle scenarios such as network loss. Let’s get right into it! One of the hardest aspects of mobile development is dealing with data synchronization. How do you handle the situation when you need to add a new broker, but you’re offline? Or what if two agents are updating the same broker: how can you handle the merging of those two changes? With the Salesforce Mobile SDK, these real-world issues are handled for you by a system called Mobile Sync. Mobile Sync has you map your phone’s local data to the data in Salesforce. It also requires you to define operations for fetching and pushing data—what it calls syncDown and syncUp. To get started with Mobile Sync, create a file in res/raw called brokerstore. json:
This file defines the shape of the data on your phone, as well as some additional metadata that’s necessary for the sync. Next, create a file called brokersync. json:
These are the operations that Mobile Sync will use when syncing data down and up. The code to complete the Mobile Sync process depends on several factors, such as when you want to perform a synchronization, as well as hooking into the Android event cycle when a device loses (and regains) connectivity.

Continue reading...