How to delete feature using apply edits in Android API?

3380
2
11-06-2015 03:43 AM
SuryaKant
New Contributor III

I am trying to delete feature from feature layer using apply edits by passing a graphic array as input, but it is showing me the error 'unable to complete operation, no adds,updates or deletes were specified'.

Also, if I am passing the same graphic for update operation then it is being updated successfully.

Following is the code snippet:

Map<String, Object> graphicAttributes = new HashMap<String, Object>();
  graphicAttributes.put("OBJECTID", 65);
 
  Graphic mfinalGraphic = new Graphic(null, null, graphicAttributes);
 


  arcGISFeatureLayer.applyEdits(null, new Graphic[]{mfinalGraphic}, null, new CallbackListener<FeatureEditResult[][]>() {
      @Override
      public void onCallback(final FeatureEditResult[][] featureEditResults) {
 
             runOnUiThread(new Runnable() {
             @Override
             public void run() {
             Toast.makeText(MainActivity.this, "Successfully deleted", Toast.LENGTH_LONG).show();
             }
  } );
  } 
 
  @Override
  public void onError(final Throwable throwable) {
  runOnUiThread(new Runnable() {
  @Override
  public void run() {
  Toast.makeText(MainActivity.this, "Failed to delete", Toast.LENGTH_LONG).show();
  }
  });
  }  });

While tracking on fiddler, I am getting the following request:

f=json&deletes=&token=BY26ICX0-KN....

The problem is at rest end if I pass only the object id in f=json&deletes=7&token=BY26ICX0-KN.... then it is getting deleted successfully.
But there is no way of passing only object id in apply edit for delete part in Android API.

Waiting for a positive reply

0 Kudos
2 Replies
DanO_Neill
Occasional Contributor III

Yes you are not passing an accurate objectId in  your code. Can you get the objectID field value from the selection?

graphicAttributes.put(arcGISFeatureLayer.getObjectIdField, SelectedGraphic.getAttributeValue(arcGISFeatureLayer.getObjectIdField));

0 Kudos
SuryaKant
New Contributor III

@Dan O'Neill: I tried your code too but I want to delete the records from REST-end feature service like (http://server:port/arcgis/rest/folder_name/service_name/FeatureServer/0). Can we delete records directly from REST-end in Android? If yes, please help with the syntax.

0 Kudos