【问题标题】:Android Azure Offline Sync - Not completing syncAndroid Azure 离线同步 - 未完成同步
【发布时间】:2017-11-14 19:13:04
【问题描述】:

我有一个带有 Azure 移动服务的 Android 应用程序并实施了离线同步。该应用程序运行良好,但在同步数据时似乎没有完成,所以表上总是有几行未同步?

任何人都知道问题可能是什么。我相信在下一次尝试时它会从中断的地方完成还是我错了?

提前致谢

【问题讨论】:

    标签: android azure synchronization azure-mobile-services


    【解决方案1】:

    应用运行良好,但在同步数据时似乎无法完成,所以表上总是有几行未同步?

    我建议您在处理同步操作时使用fiddler 来捕获网络跟踪。

    对于Incremental Sync,请求如下:

    Get https://{your-app-name}.azurewebsites.net/tables/TodoItem?$filter=(updatedAt%20ge%20datetimeoffset'2017-11-03T06%3A56%3A44.4590000%2B00%3A00')&$orderby=updatedAt&$skip=0&$top=50&__includeDeleted=true 
    

    要选择退出增量同步,您将检索没有过滤器 updatedAt 的所有记录。

    Get https://{your-app-name}.azurewebsites.net/tables/TodoItem?$skip=0&$top=50&__includeDeleted=true 
    

    注意:如果项目太多,SDK 会发送多个请求以从关联的远程表中提取与给定查询匹配的所有项目。此外,您需要确保在查询中指定 includeDeleted()

    总之,您需要确保可以通过上述请求检索所有项目。此外,如果拉取操作有待处理的本地更新,那么拉取操作将首先执行推送操作。所以,我假设你可以在调用 pull 操作来处理冲突解决时捕获异常。

    【讨论】:

      【解决方案2】:

      Bruce 的回答很好,但我使用了稍微不同的方法,无需使用 fiddler。

      我从此改变了我的连接

      mClient = new MobileServiceClient("[AZUREWEBSITE]", cntxall);
                      mClient.setAndroidHttpClientFactory(new MyOkHttpClientFactory());
      

      到这里

      mClient = new MobileServiceClient("[AZUREWEBSITE]", cntxall).withFilter(
                              new ServiceFilter() {
                                  @Override
                                  public ListenableFuture<ServiceFilterResponse> handleRequest(ServiceFilterRequest request, NextServiceFilterCallback nextServiceFilter) {
                                      // Get the request contents
                                      String url = request.getUrl();
                                      String content = request.getContent();
      
                                      if (url != null) {
                                          Log.d("Request URL:", url);
                                      }
      
                                      if (content != null) {
                                          Log.d("Request Content:", content);
                                      }
      
                                      // Execute the next service filter in the chain
                                      ListenableFuture<ServiceFilterResponse> responseFuture = nextServiceFilter.onNext(request);
      
                                      Futures.addCallback(responseFuture, new FutureCallback<ServiceFilterResponse>() {
                                          @Override
                                          public void onFailure(Throwable e) {
                                              Log.d("Exception:", e.getMessage());
                                          }
      
                                          @Override
                                          public void onSuccess(ServiceFilterResponse response) {
                                              if (response != null && response.getContent() != null) {
                                                  Log.d("Response Content:", response.getContent());
                                              }
                                          }
                                      });
      
                                      return responseFuture;
                                  }
                              }
                      );
      

      这是 Azure 连接的记录方法,并在日志中显示请求。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-04-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多