Search code examples
android.netazuresoft-delete

Android Azure Mobile Services Offline Sync Soft Delete


I've implemented an Android App which supports Azure Mobile Services and Offline Sync. I have been testing it with two different devices. I do a delete operation (soft delete) on the first device and that works ok. I then let it sync, check the server side record that the Deleted column has 'true' marked which it does. But I cannot seem to get the second tablet to sync to reflect the new changes i.e. do not display the deleted record.

To enable soft delete I have added enableSoftDelete: true into the table controllers on the app service on Azure. I've not touched my app in terms of the delete process but below is a typical delete:

    Save save = getSave(SaveID);
try {
            mtblSave.delete(save);
            return true;

        } catch (Exception exception) {
            exception.printStackTrace();
            return false;
        }

I'm using .NET backend with Azure SQL Server.

Any ideas?

Thanks in advance


Solution

  • But I cannot seem to get the second tablet to sync to reflect the new changes i.e. do not display the deleted record.

    As Using soft delete in Mobile Services mentioned as follows:

    When using the Offline data Sync for Mobile Services feature, the client SDK automatically queries for deleted records and removes them from the local database. Without soft delete enabled, you need to write additional code on the backend so that the client SDK knows which records to remove from the local store. Otherwise, the client local store and backend will be inconsistent with regard to these deleted records and the client method PurgeAsync() must be called to clear the local store.

    I assumed that you could leverage fiddler to capture the network traces when handling pull operation. Also, you could add includeDeleted method when you construct the query for pulling data as follows for a better understanding of this feature.

    var pullQuery = mClient.getTable(ToDoItem.class).where().field("complete").eq(false).includeDeleted();
    mToDoTable.pull(mPullQuery).get();
    

    Additionally, for more details about using offline data sync in Mobile Services, you could refer to here.

    UPDATE:

    The query parameter is an optional query to filter results.

    As How offline synchronization works mentioned about Incremental Sync:

    If you use a non-null queryId, the Azure Mobile SDK performs an incremental sync. Each time a pull operation returns a set of results, the latest updatedAt timestamp from that result set is stored in the SDK local system tables. Subsequent pull operations retrieve only records after that timestamp.

    The query name can be any string you choose, but it must be unique for each logical query in your app. Otherwise, different pull operations could overwrite the same incremental sync timestamp and your queries can return incorrect results.

    You could refer to this answer and troubleshoot your issue.