title: How to sync enqueued data before getting data from aws amplify
body: <p>On my app log in process, I have a service that get the latest datas from aws amplify
  <a href="https://docs.amplify.aws/lib/datastore/datastore-events/q/platform/js/#networkstatus" rel="nofollow noreferrer">DataStore Events</a></p>
  <pre><code>private String processName = &quot;Checking network status...&quot;;
  
  private SubscriptionToken subscriptionToken;
  
  public void sync() {
  
      AmplifyDataStoreManager.start();
  
      subscriptionToken = Amplify.Hub.subscribe(
              HubChannel.DATASTORE,
              hubEvent -&gt; DataStoreChannelEventName.NETWORK_STATUS.toString().equals(hubEvent.getName()) ||
                      DataStoreChannelEventName.SUBSCRIPTION_DATA_PROCESSED.toString().equals(hubEvent.getName()) ||
                      DataStoreChannelEventName.MODEL_SYNCED.toString().equals(hubEvent.getName()) ||
                      DataStoreChannelEventName.READY.toString().equals(hubEvent.getName()),
              hubEvent -&gt; {
  
                  Log.d(&quot;DataStore - Hub Event Name: &quot; + hubEvent.getName());
  
                  if (hubEvent.getData() != null) {
                      Log.d(&quot;DataStore - Hub Event Data: &quot; + hubEvent.getData());
                  }
  
                  if (DataStoreChannelEventName.NETWORK_STATUS.toString().equals(hubEvent.getName())) {
  
                      NetworkStatusEvent networkStatusEvent = (NetworkStatusEvent) hubEvent.getData();
  
                      if (networkStatusEvent != null &amp;&amp; !networkStatusEvent.getActive()) {
  
                          onProcessError(&quot;Device not connected to internet&quot;);
  
                      }
  
                  } else if (DataStoreChannelEventName.SUBSCRIPTION_DATA_PROCESSED.toString().equals(hubEvent.getName())) {
  
                      ModelWithMetadata modelWithMetadata = ((ModelWithMetadata) hubEvent.getData());
  
                      ModelMetadata modelMetadata = modelWithMetadata.getSyncMetadata();
  
                      Log.d(&quot;DataStore - Model ID: &quot; + modelWithMetadata.getModel().getId());
  
                      Log.d(&quot;DataStore - Model Name: &quot; + modelWithMetadata.getModel().getModelName());
  
                      processName = &quot;Syncing &quot; +  modelWithMetadata.getModel().getModelName() + &quot;...&quot;;
  
                      EventBus.getDefault().post(new ProcessEvent(this));
  
                      if (TextUtils.equals(AmplifyDataModel.Transaction.name(), modelWithMetadata.getModel().getModelName()) &amp;&amp; (modelMetadata.isDeleted() == null || !modelMetadata.isDeleted())) {
  
                          AppAmplifyDataAccessManager.saveAppTransaction(AppAmplifyConfiguration.getDataSyncManager().mapAppTransaction(modelWithMetadata.getModel()));
  
                      } else if (TextUtils.equals(AmplifyDataModel.Configuration.name(), modelWithMetadata.getModel().getModelName()) &amp;&amp; (modelMetadata.isDeleted() == null || !modelMetadata.isDeleted())) {
  
                          AppAmplifyConfiguration.getDataSyncManager().mapConfigurations(modelWithMetadata.getModel());
                      }
  
                  } else if (DataStoreChannelEventName.MODEL_SYNCED.toString().equals(hubEvent.getName())) {
  
                      ModelSyncedEvent modelSyncedEvent = (ModelSyncedEvent) hubEvent.getData();
  
                      if (modelSyncedEvent != null) {
  
                          processName = &quot;Syncing &quot; +  modelSyncedEvent.getModel() + &quot;...&quot;;
  
                          EventBus.getDefault().post(new ProcessEvent(this));
  
                      }
  
                  } else {
  
                      Amplify.Hub.unsubscribe(subscriptionToken);
  
                      onProcessCompleted();
                  }
  
              }
      );
  }
  </code></pre>
  <p>Configuration Model data sample:<br></p>
  <pre><code>double grandTotal;
  </code></pre>
  <p>aws configuration: grandTotal = 100;<br>
  local configuration: grandTotal = 100;</p>
  <p>The scenario is, the device is offline, did transaction, local configuration: grandTotal is now 200. The sync configuration is called and enqueued because the device is offline.
  Closed the app, the internet is back, opens the app, in the login process, sync() method is called. What happens is the local configuration: grandTotal is 100 again, because of sync(), then after that, the enqueued sync when the device is offline runs(but I was not able to debug this, its not going to the sync method of configuration). And the result is:</p>
  <p>aws configuration: grandTotal = 200;<br>
  local configuration: grandTotal = 100;</p>
  <p>What I want is if there is a pending sync, do that first before syncing aws data to local.</p>