如何在Android的azure同步过程中正确解决冲突?

时间:2018-03-06 09:30:04

标签: android azure

我遇到了azure同步问题,我能够通过mCLient.getSyncContext().getPendingOperations();检测到待处理操作的数量但无法解决它们。有任何帮助或建议吗?

2 个答案:

答案 0 :(得分:1)

在离线方案中使用并且您有待处理操作时,可以使用push()功能将它们推送到服务器。

它看起来像下面这样:

try {
    MobileServiceSyncContext syncContext = mClient.getSyncContext();
    syncContext.push().get();

    // here you would do a pull on any table you want to grab data from
}
catch (final MobileServiceConflictException e)
{
    // the server item causing the exception can be obtained by calling e.getItem()
    JsonObject serverObject = e.getItem();

    // on the sync context, call one of the following:

    // .cancelAndDiscardItem() to cancel update and discard local item

    // .cancelAndUpdateItem() to update the local item with the server's copy

    // .cancelAndUpdateItem(JsonObject item) to update the server's item w/ the local

    // make sure to call push() again on the sync context
}

总而言之 - 请务必致电push()上的MobileServiceSyncContext,然后处理可能会返回的MobileServiceConflictException

答案 1 :(得分:0)

如果我抓到MobileServiceConflictException,android studio会告诉我在相应的try块中永远不会抛出异常。

localStorage.setItem('userdata','lib4')
console.log( localStorage.getItem('userdata') )