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

问题描述 投票:0回答:2

我在azure同步方面遇到麻烦,我能够通过mCLient.getSyncContext().getPendingOperations();检测到挂起的操作数,但无法解决它们。任何帮助或建议?

android azure
2个回答
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


0
投票

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

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

                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    } catch (ExecutionException e) {
                        e.printStackTrace();
                    } catch (MobileServiceConflictException e) {

                    }
© www.soinside.com 2019 - 2024. All rights reserved.