Delete features (feature service)

View inJavaKotlinView on GitHubSample viewer app

Delete features from an online feature service.

Image of delete features feature service

Use case

Sometimes users may want to delete features from an online feature service.

How to use the sample

Tap on a feature on the map and tap the trash icon to delete it.

How it works

  1. Create a ServiceFeatureTable object from a URL.
  2. Create a FeatureLayer object from the ServiceFeatureTable.
  3. Select features from the FeatureTable via queryFeaturesAsync().
  4. Remove the selected features from the ServiceFeatureTable using deleteFeaturesAsync().
  5. Update the table on the server using applyEditsAsync().

Relevant API

  • Feature
  • FeatureLayer
  • ServiceFeatureTable

Tags

deletion, feature, online, Service, table

Sample Code

ConfirmDeleteFeatureDialog.javaConfirmDeleteFeatureDialog.javaMainActivity.java
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
 * Copyright 2019 Esri
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.esri.arcgisruntime.samples.deletefeaturesfeatureservice;

import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.DialogFragment;
import androidx.appcompat.app.AlertDialog;

public class ConfirmDeleteFeatureDialog extends DialogFragment {

  private static final String ARG_FEATURE_ID = ConfirmDeleteFeatureDialog.class.getSimpleName() + "_feature_id";

  private String featureId;

  private final DialogInterface.OnClickListener mOnClickListener = (dialog, which) -> {
    if (getContext() instanceof OnButtonClickedListener) {
      if (which == DialogInterface.BUTTON_POSITIVE) {
        ((OnButtonClickedListener) getContext()).onDeleteFeatureClicked(featureId);
      } else {
        dismiss();
      }
    }
  };

  public static ConfirmDeleteFeatureDialog newInstance(String featureId) {
    ConfirmDeleteFeatureDialog fragment = new ConfirmDeleteFeatureDialog();
    Bundle args = new Bundle();
    args.putString(ARG_FEATURE_ID, featureId);
    fragment.setArguments(args);
    return fragment;
  }

  @Override public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.featureId = getArguments().getString(ARG_FEATURE_ID);
  }

  @NonNull @Override public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
    return new AlertDialog.Builder(getContext())
        .setMessage(getString(R.string.dialog_confirm_delete_message, featureId))
        .setPositiveButton(R.string.dialog_confirm_delete_positive, mOnClickListener)
        .setNegativeButton(R.string.dialog_confirm_delete_negative, mOnClickListener)
        .create();
  }

  public interface OnButtonClickedListener {
    void onDeleteFeatureClicked(String featureId);
  }

}

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.