<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Loop and apply edit in ArcGIS Runtime SDK for Android Questions</title>
    <link>https://community.esri.com/t5/arcgis-runtime-sdk-for-android-questions/loop-and-apply-edit/m-p/1080039#M5557</link>
    <description>&lt;P&gt;I have done the indicated but not all the features get out of the loop to the server.&lt;BR /&gt;apparently it is a bug since within the loop they all reach the server but are duplicated, in version 10.X this problem did not occur.&lt;/P&gt;</description>
    <pubDate>Sun, 18 Jul 2021 00:52:04 GMT</pubDate>
    <dc:creator>NicolasElgueta</dc:creator>
    <dc:date>2021-07-18T00:52:04Z</dc:date>
    <item>
      <title>Loop and apply edit</title>
      <link>https://community.esri.com/t5/arcgis-runtime-sdk-for-android-questions/loop-and-apply-edit/m-p/1076878#M5547</link>
      <description>&lt;P&gt;Hello everyone, I have the following problem, I read from a data array and what I want to do is go through the at create the geometry and send it through a feature service.&lt;BR /&gt;Everything works for me ok, except that my shipments are duplicated.&lt;/P&gt;&lt;P&gt;I am attaching my code to see if someone can help me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="java"&gt; private void sendData(){
        ServiceFeatureTable featureTable;
        featureTable = mServiceFeatureTable;

                for (RepartoClass rep : arrayData){
                    Integer myId = rep.getId();

                    Map&amp;lt;String, Object&amp;gt; attributes = new HashMap&amp;lt;&amp;gt;();
                    attributes.put( "nis", rep.getNis() );
                    attributes.put( "valor_captura", rep.getCodigo() );
                    attributes.put( "empresa", empresa );
                    attributes.put( "modulo", rep.getTipo() );
                    attributes.put( "fecha", rep.getFecha() );

                    String oTipo;
                    oTipo = rep.getTipo();

                    Point oUbicacion = new Point( rep.getX(), rep.getY(), SpatialReference.create( 32719 ) );

                   
                            featureTable.addDoneLoadingListener( () -&amp;gt; {
                                Feature feature = featureTable.createFeature( attributes, oUbicacion );
                                if (featureTable.canAdd()) {
                                    myDeletes.add( myId );
                                    //featureTable.addFeatureAsync( feature ).addDoneListener( () -&amp;gt; applyEdits( featureTable ) );
                                    featureTable.addFeatureAsync( feature );
                                }
                            } );
                }

        featureTable.loadAsync();
        final ListenableFuture&amp;lt;List&amp;lt;FeatureEditResult&amp;gt;&amp;gt; editResult = featureTable.applyEditsAsync();
        editResult.addDoneListener( () -&amp;gt; {
            try {
                List&amp;lt;FeatureEditResult&amp;gt; editResults = editResult.get();
                //Check if the server edit succeful
                if (editResults != null &amp;amp;&amp;amp; !editResults.isEmpty()) {
                    if (!editResults.get( 0 ).hasCompletedWithErrors()) {                       
                    } else {
                        throw editResults.get( 0 ).getError();
                    }
                }
            } catch (InterruptedException | ExecutionException e) {
                runOnUiThread( () -&amp;gt; logToUser( true, "ErrorApply:" + e.getCause().getMessage() ) );
            }
        } );       
    }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Jul 2021 18:03:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-runtime-sdk-for-android-questions/loop-and-apply-edit/m-p/1076878#M5547</guid>
      <dc:creator>NicolasElgueta</dc:creator>
      <dc:date>2021-07-08T18:03:40Z</dc:date>
    </item>
    <item>
      <title>Re: Loop and apply edit</title>
      <link>https://community.esri.com/t5/arcgis-runtime-sdk-for-android-questions/loop-and-apply-edit/m-p/1078082#M5552</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Could you try &amp;amp; move your for loop within the featuretable done listener. You only need to load the feature table once. And make sure addFeatures only add's the required number of features and applyEdits is only called once after all the features you need are added to the feature table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Rama&lt;/P&gt;</description>
      <pubDate>Mon, 12 Jul 2021 23:42:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-runtime-sdk-for-android-questions/loop-and-apply-edit/m-p/1078082#M5552</guid>
      <dc:creator>RamaChintapalli</dc:creator>
      <dc:date>2021-07-12T23:42:16Z</dc:date>
    </item>
    <item>
      <title>Re: Loop and apply edit</title>
      <link>https://community.esri.com/t5/arcgis-runtime-sdk-for-android-questions/loop-and-apply-edit/m-p/1080039#M5557</link>
      <description>&lt;P&gt;I have done the indicated but not all the features get out of the loop to the server.&lt;BR /&gt;apparently it is a bug since within the loop they all reach the server but are duplicated, in version 10.X this problem did not occur.&lt;/P&gt;</description>
      <pubDate>Sun, 18 Jul 2021 00:52:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-runtime-sdk-for-android-questions/loop-and-apply-edit/m-p/1080039#M5557</guid>
      <dc:creator>NicolasElgueta</dc:creator>
      <dc:date>2021-07-18T00:52:04Z</dc:date>
    </item>
    <item>
      <title>Re: Loop and apply edit</title>
      <link>https://community.esri.com/t5/arcgis-runtime-sdk-for-android-questions/loop-and-apply-edit/m-p/1081184#M5561</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I tried below code with a sample service and it seem's to work fine as expected (i.e add all features in loop and apply them to server only once).&lt;BR /&gt;&lt;BR /&gt;Sample Service:&amp;nbsp;&lt;A href="https://sampleserver6.arcgisonline.com/arcgis/rest/services/DamageAssessment/FeatureServer/0" target="_blank" rel="noopener"&gt;https://sampleserver6.arcgisonline.com/arcgis/rest/services/DamageAssessment/FeatureServer/0&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="java"&gt;private void addFeaturesInALoop() {

    mServiceFeatureTable.addDoneLoadingListener( () -&amp;gt; {
      int i = 0;

      for (i=0;i&amp;lt;3;i++){
        FeatureType featureType = mServiceFeatureTable.getFeatureTypes().get(0);

        Feature feature = mServiceFeatureTable.createFeature(featureType);
        if (mServiceFeatureTable.canAdd()) {
          try {
            mServiceFeatureTable.addFeatureAsync(feature).get();
          } catch (Exception e) {
            e.printStackTrace();
          }
        }
      }
      applyEditsToServer();
    } );
    mServiceFeatureTable.loadAsync();

  }

  /**
   * Applies edits to the FeatureService
   */
  private void applyEditsToServer() {
    final ListenableFuture&amp;lt;List&amp;lt;FeatureEditResult&amp;gt;&amp;gt; applyEditsFuture = ((ServiceFeatureTable) mFeatureLayer
        .getFeatureTable()).applyEditsAsync();
    applyEditsFuture.addDoneListener(() -&amp;gt; {
      try {
        // get results of edit
        List&amp;lt;FeatureEditResult&amp;gt; featureEditResultsList = applyEditsFuture.get();
        if (!featureEditResultsList.get(0).hasCompletedWithErrors()) {
          Toast.makeText(this,
              "Applied Edits to Server. ObjectID: " + featureEditResultsList.get(0).getObjectId(),
              Toast.LENGTH_SHORT).show();
        }
      } catch (InterruptedException | ExecutionException e) {
        Log.e(TAG, "Update feature failed: " + e.getMessage());
      }
    });
  }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;Rama&lt;/P&gt;</description>
      <pubDate>Wed, 21 Jul 2021 05:48:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-runtime-sdk-for-android-questions/loop-and-apply-edit/m-p/1081184#M5561</guid>
      <dc:creator>RamaChintapalli</dc:creator>
      <dc:date>2021-07-21T05:48:09Z</dc:date>
    </item>
    <item>
      <title>Re: Loop and apply edit</title>
      <link>https://community.esri.com/t5/arcgis-runtime-sdk-for-android-questions/loop-and-apply-edit/m-p/1088762#M5593</link>
      <description>&lt;P&gt;Hi Rama,&amp;nbsp;can see that you are looping an existing featuretable, I try to loop a sqlLite database and create a feature from the existing array data in the database, then send.&lt;/P&gt;&lt;P&gt;When doing this reading of data from bd sqllite with the following code, I get the following error indicating that it cannot find a record.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="java"&gt; private void enviarDatos() {

        mServiceFeatureTable.addDoneLoadingListener( () -&amp;gt; {
           
        for (RepartoClass rep : arrayDatos) {
            Map&amp;lt;String, Object&amp;gt; attributes = new HashMap&amp;lt;&amp;gt;();
            attributes.put( "nis", rep.getNis() );
            attributes.put( "valor_captura", rep.getCodigo() );
            attributes.put( "empresa", empresa );
            attributes.put( "modulo", rep.getTipo() );
            attributes.put( "fecha", rep.getFecha() );

            String oTipo;
            oTipo = rep.getTipo();

            Point oUbicacion = new Point( rep.getX(), rep.getY(), SpatialReference.create( 32719 ) );
            switch (oTipo) {
                case "BOL":
                    Feature featureBoleta = mServiceFeatureTable.createFeature(attributes,oUbicacion);
                    if(mServiceFeatureTable.canAdd()){
                        try {
                            mServiceFeatureTable.addFeatureAsync( featureBoleta ).get();
                        } catch (Exception w) {
                            w.printStackTrace();
                        }
                    }
                case "MDV":
                    Feature featureCarta = mServiceFeatureTableCarta.createFeature(attributes,oUbicacion);
                    if(mServiceFeatureTableCarta.canAdd()){
                        try{
                            mServiceFeatureTableCarta.addFeatureAsync( featureCarta ).get();
                        }catch (Exception w){
                            w.printStackTrace();
                        }

                    }
            }
        }            
        } );
        applyEditsToServer3();
    }

    private void applyEditsToServer3() {
        final ListenableFuture&amp;lt;List&amp;lt;FeatureEditResult&amp;gt;&amp;gt; applyEditsFuture =((ServiceFeatureTable) featureLayerBoleta.getFeatureTable()).applyEditsAsync();
        applyEditsFuture.addDoneListener( () -&amp;gt; {
            try {
                List&amp;lt;FeatureEditResult&amp;gt; featureEditResultList = applyEditsFuture.get();
                if(!featureEditResultList.get( 0 ).hasCompletedWithErrors()){
                    Toast.makeText( this,"Applied Edits to server ObjectID: " + featureEditResultList.get( 0 ).getObjectId() ,Toast.LENGTH_SHORT).show();
                }
            }catch (InterruptedException| ExecutionException e){
                Log.e(TAG,"Update feature failed: " + e.getMessage());
            }
        } );
    }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="java"&gt;E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.giscen.gisred, PID: 20646
    java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
        at java.util.ArrayList.get(ArrayList.java:437)
        at com.esri.arcgisruntime.a.q.i0.get(SourceFile:1)
        at com.giscen.gisred.RepartoActivity.lambda$applyEditsToServer3$3$RepartoActivity(RepartoActivity.java:470)
        at com.giscen.gisred.-$$Lambda$RepartoActivity$8PkwM4RtkThdsT-H59pLFI8r0xM.run(Unknown Source:4)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7073)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can't get to success&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Nicolas&lt;/P&gt;</description>
      <pubDate>Fri, 13 Aug 2021 04:26:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-runtime-sdk-for-android-questions/loop-and-apply-edit/m-p/1088762#M5593</guid>
      <dc:creator>NicolasElgueta</dc:creator>
      <dc:date>2021-08-13T04:26:47Z</dc:date>
    </item>
  </channel>
</rss>

