Add features with contingent values

View on GitHub
Sample viewer app

Create and add features whose attribute values satisfy a predefined set of contingencies.

Add features with contingent values Add contingent feature

Use case

Contingent values are a data design feature that allow you to make values in one field dependent on values in another field. Your choice for a value on one field further constrains the domain values that can be placed on another field. In this way, contingent values enforce data integrity by applying additional constraints to reduce the number of valid field inputs.

For example, a field crew working in a sensitive habitat area may be required to stay a certain distance away from occupied bird nests, but the size of that exclusion area differs depending on the bird's level of protection according to presiding laws. Surveyors can add points of bird nests in the work area and their selection of the size of the exclusion area will be contingent on the values in other attribute fields.

How to use the sample

Tap on the map to add a feature symbolizing a bird's nest. Then choose values describing the nest's status, protection, and buffer size. Notice how different values are available depending on the values of preceding fields. Once the contingent values are validated, tap "Done" to add the feature to the map.

How it works

  1. Create and load the Geodatabase from the mobile geodatabase location on file.
  2. Load the first GeodatabaseFeatureTables as an ArcGISFeatureTable.
  3. Load the ContingentValuesDefinition from the feature table.
  4. Create a new FeatureLayer from the feature table and add it to the map.
  5. Create a new ArcGISFeature using ArcGISFeature.createFeature()
  6. Get the first field by name using ArcGISFeatureTable.fields.find{ }.
  7. Then get the Field.domain as an CodedValueDomain.
  8. Get the coded value domain's codedValues to get an array of CodedValue's.
  9. After selecting a value from the initial coded values for the first field, retrieve the remaining valid contingent values for each field as you select the values for the attributes.
    i. Get the ContingentValueResults by using ArcGISFeatureTable.getContingentValues(ArcGISFeature, "field_name") with the feature and the target field by name.
    ii. Get an array of valid ContingentValues from ContingentValuesResult.contingentValuesByFieldGroup dictionary with the name of the relevant field group.
    iii. Iterate through the array of valid contingent values to create an array of ContingentCodedValue names or the minimum and maximum values of a ContingentRangeValue depending on the type of ContingentValue returned.
  10. Validate the feature's contingent values by using validateContingencyConstraints(feature) with the current feature. If the resulting array is empty, the selected values are valid.

Relevant API

  • ArcGISFeatureTable
  • CodedValue
  • CodedValueDomain
  • ContingencyConstraintViolation
  • ContingentCodedValue
  • ContingentRangeValue
  • ContingentValuesDefinition
  • ContingentValuesResult

Offline data

This sample uses the Contingent values birds nests mobile geodatabase and the Fillmore topographic map vector tile package for the basemap.

  1. Download the mobile geodatabase from ArcGIS Online.
  2. Download the vector tile package from ArcGIS Online.
  3. Open your command prompt and navigate to the folder where you extracted the contents of the data from step 1.
  4. Execute the following command:

adb push FillmoreTopographicMap.vtpk /Android/data/com.esri.arcgisruntime.sample.addfeatureswithcontingentvalues/files/FillmoreTopographicMap.vtpk 5. Execute the following command: adb push ContingentValuesBirdNests.geodatabase /Android/data/com.esri.arcgisruntime.sample.addfeatureswithcontingentvalues/files/ContingentValuesBirdNests.geodatabase

Link Local Location
FillmoreTopographicMap.vtpk <sdcard>/Android/data/com.esri.arcgisruntime.sample.addfeatureswithcontingentvalues/files/FillmoreTopographicMap.vtpk
ContingentValuesBirdNests.geodatabase <sdcard>/Android/data/com.esri.arcgisruntime.sample.addfeatureswithcontingentvalues/files/ContingentValuesBirdNests.geodatabase

About the data

The mobile geodatabase contains birds nests in the Fillmore area, defined with contingent values. Each feature contains information about its status, protection, and buffer size.

Additional information

Learn more about contingent values and how to utilize them on the ArcGIS Pro documentation.

Tags

coded values, contingent values, feature table, geodatabase

Sample Code

MainActivity.kt
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
/* Copyright 2022 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.sample.addfeatureswithcontingentvalues

import android.graphics.Color
import android.os.Bundle
import android.util.Log
import android.view.MotionEvent
import android.view.ViewGroup
import android.widget.ArrayAdapter
import android.widget.AutoCompleteTextView
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.esri.arcgisruntime.ArcGISRuntimeEnvironment
import com.esri.arcgisruntime.data.ArcGISFeature
import com.esri.arcgisruntime.data.ArcGISFeatureTable
import com.esri.arcgisruntime.data.CodedValue
import com.esri.arcgisruntime.data.CodedValueDomain
import com.esri.arcgisruntime.data.ContingentCodedValue
import com.esri.arcgisruntime.data.ContingentRangeValue
import com.esri.arcgisruntime.data.Feature
import com.esri.arcgisruntime.data.Geodatabase
import com.esri.arcgisruntime.data.QueryParameters
import com.esri.arcgisruntime.geometry.GeometryEngine
import com.esri.arcgisruntime.geometry.Point
import com.esri.arcgisruntime.layers.ArcGISVectorTiledLayer
import com.esri.arcgisruntime.layers.FeatureLayer
import com.esri.arcgisruntime.loadable.LoadStatus
import com.esri.arcgisruntime.mapping.ArcGISMap
import com.esri.arcgisruntime.mapping.Basemap
import com.esri.arcgisruntime.mapping.Viewpoint
import com.esri.arcgisruntime.mapping.view.DefaultMapViewOnTouchListener
import com.esri.arcgisruntime.mapping.view.Graphic
import com.esri.arcgisruntime.mapping.view.GraphicsOverlay
import com.esri.arcgisruntime.mapping.view.MapView
import com.esri.arcgisruntime.sample.addfeatureswithcontingentvalues.databinding.ActivityMainBinding
import com.esri.arcgisruntime.sample.addfeatureswithcontingentvalues.databinding.AddFeatureLayoutBinding
import com.esri.arcgisruntime.symbology.SimpleFillSymbol
import com.esri.arcgisruntime.symbology.SimpleLineSymbol
import com.esri.arcgisruntime.symbology.SimpleMarkerSymbol
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog
import java.io.File

class MainActivity : AppCompatActivity() {

    private val TAG: String = MainActivity::class.java.simpleName

    private val activityMainBinding by lazy {
        ActivityMainBinding.inflate(layoutInflater)
    }

    private val bottomSheetBinding by lazy {
        AddFeatureLayoutBinding.inflate(layoutInflater)
    }

    private val mapView: MapView by lazy {
        activityMainBinding.mapView
    }

    // graphic overlay instance to add the feature graphic to the map
    private val graphicsOverlay = GraphicsOverlay()

    // mobile database containing offline feature data. GeoDatabase is closed on app exit
    private var geoDatabase: Geodatabase? = null

    // instance of the contingent feature to be added to the map
    private var feature: ArcGISFeature? = null

    // instance of the feature table retrieved from the GeoDatabase, updates when new feature is added
    private var featureTable: ArcGISFeatureTable? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(activityMainBinding.root)

        // authentication with an API key or named user is required to access basemaps and other location services
        ArcGISRuntimeEnvironment.setApiKey(BuildConfig.API_KEY)

        // create a temporary directory to use the geodatabase file
        createGeodatabaseCacheDirectory()

        // use the offline vector tiled layer as a basemap
        val fillmoreVectorTiledLayer = ArcGISVectorTiledLayer(
            getExternalFilesDir(null)?.path + "/FillmoreTopographicMap.vtpk"
        )
        mapView.apply {
            // set the basemap layer and the graphic overlay to the MapView
            map = ArcGISMap(Basemap(fillmoreVectorTiledLayer))
            graphicsOverlays.add(graphicsOverlay)

            // add a listener to the MapView to detect when a user has performed a single tap to add a new feature
            onTouchListener = object : DefaultMapViewOnTouchListener(this@MainActivity, this) {
                override fun onSingleTapConfirmed(motionEvent: MotionEvent?): Boolean {
                    motionEvent?.let { event ->
                        // create a point from where the user clicked
                        android.graphics.Point(event.x.toInt(), event.y.toInt()).let { point ->
                            // create a map point and add a new feature to the service feature table
                            openBottomSheetView(screenToLocation(point))
                        }
                    }
                    performClick()
                    return super.onSingleTapConfirmed(motionEvent)
                }
            }
        }

        // retrieve and load the offline mobile GeoDatabase file from the cache directory
        geoDatabase = Geodatabase(cacheDir.path + "/ContingentValuesBirdNests.geodatabase")
        geoDatabase?.loadAsync()
        geoDatabase?.addDoneLoadingListener {
            if (geoDatabase?.loadStatus == LoadStatus.LOADED) {
                (geoDatabase?.geodatabaseFeatureTables?.first() as? ArcGISFeatureTable)?.let { featureTable ->
                    this.featureTable = featureTable
                    featureTable.loadAsync()
                    featureTable.addDoneLoadingListener {
                        // create and load the feature layer from the feature table
                        val featureLayer = FeatureLayer(featureTable)
                        // add the feature layer to the map
                        mapView.map.operationalLayers.add(featureLayer)
                        // set the map's viewpoint to the feature layer's full extent
                        val extent = featureLayer.fullExtent
                        mapView.setViewpoint(Viewpoint(extent))
                        // add buffer graphics for the feature layer
                        queryFeatures()
                    }
                }

            } else {
                val error = "Error loading GeoDatabase: " + geoDatabase?.loadError?.message
                Toast.makeText(this, error, Toast.LENGTH_SHORT).show()
                Log.e(TAG, error)
            }
        }
    }

    /**
     * Geodatabase creates and uses various temporary files while processing a database,
     * which will need to be cleared before looking up the [geoDatabase] again. A copy of the original geodatabase
     * file is created in the cache folder.
     */
    private fun createGeodatabaseCacheDirectory() {
        try{
            // clear cache directory
            File(cacheDir.path).deleteRecursively()
            // copy over the original Geodatabase file to be used in the temp cache directory
            File(getExternalFilesDir(null)?.path + "/ContingentValuesBirdNests.geodatabase").copyTo(
                File(cacheDir.path + "/ContingentValuesBirdNests.geodatabase")
            )
        }catch (e: Exception){
            val message = "Error setting .geodatabase file: " + e.message
            Log.e(TAG, message)
            Toast.makeText(this, message, Toast.LENGTH_SHORT).show()
        }
    }

    /**
     * Create buffer graphics for the features and adds the graphics to
     * the [graphicsOverlay]
     */
    private fun queryFeatures() {
        // create buffer graphics for the features
        val queryParameters = QueryParameters().apply {
            // set the where clause to filter for buffer sizes greater than 0
            whereClause = "BufferSize > 0"
        }
        // query the features using the queryParameters on the featureTable
        val queryFeaturesFuture = featureTable?.queryFeaturesAsync(queryParameters)
        queryFeaturesFuture?.addDoneListener {
            try {
                // clear the existing graphics
                graphicsOverlay.graphics.clear()
                // call get on the future to get the result
                val resultIterator = queryFeaturesFuture.get().iterator()
                if (resultIterator.hasNext()) {
                    // create an array of graphics to add to the graphics overlay
                    val graphics = mutableListOf<Graphic>()
                    // create graphic for each query result by calling createGraphic(feature)
                    //while (resultIterator.hasNext()) graphics.add(createGraphic(resultIterator.next()))
                    queryFeaturesFuture.get().iterator().forEach {
                        graphics.add(createGraphic(it))
                    }
                    // add the graphics to the graphics overlay
                    graphicsOverlay.graphics.addAll(graphics)
                } else {
                    val message = "No features found with BufferSize > 0"
                    Toast.makeText(this, message, Toast.LENGTH_LONG).show()
                    Log.d(TAG, message)
                }
            } catch (e: Exception) {
                val message = "Error querying features: " + e.message
                Log.e(TAG, message)
                Toast.makeText(this, message, Toast.LENGTH_SHORT).show()
            }
        }
    }

    /**
     * Create a graphic for the given [feature] and returns a Graphic with the features attributes
     */
    private fun createGraphic(feature: Feature): Graphic {
        // get the feature's buffer size
        val bufferSize = feature.attributes["BufferSize"] as Int
        // get a polygon using the feature's buffer size and geometry
        val polygon = GeometryEngine.buffer(feature.geometry, bufferSize.toDouble())
        // create the outline for the buffers
        val lineSymbol = SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, Color.BLACK, 2F)
        // create the buffer symbol
        val bufferSymbol = SimpleFillSymbol(
            SimpleFillSymbol.Style.FORWARD_DIAGONAL, Color.RED, lineSymbol
        )
        // create an a graphic and add it to the array.
        return Graphic(polygon, bufferSymbol)
    }

    /**
     * Open BottomSheetDialog view to handle contingent value interaction.
     * Once the contingent values have been set and the apply button is clicked,
     * the function will call validateContingency() to add the feature to the map.
     */
    private fun openBottomSheetView(mapPoint: Point) {
        // creates a new BottomSheetDialog
        val dialog = BottomSheetDialog(this)
        dialog.behavior.state = BottomSheetBehavior.STATE_EXPANDED

        // set up the first content value attribute
        setUpStatusAttributes()

        bottomSheetBinding.apply {
            // reset bottom sheet values, this is needed to showcase contingent values behavior
            statusInputLayout.editText?.setText("")
            protectionInputLayout.editText?.setText("")
            selectedBuffer.text = ""
            protectionInputLayout.isEnabled = false
            bufferSeekBar.isEnabled = false
            bufferSeekBar.value = bufferSeekBar.valueFrom

            // set apply button to validate and apply contingency feature on map
            applyTv.setOnClickListener {
                // check if the contingent features set is valid and set it to the map if valid
                validateContingency(mapPoint)
                dialog.dismiss()
            }
            // dismiss on cancel clicked
            cancelTv.setOnClickListener { dialog.dismiss() }
        }
        // clear and set bottom sheet content view to layout, to be able to set the content view on each bottom sheet draw
        if (bottomSheetBinding.root.parent != null) {
            (bottomSheetBinding.root.parent as ViewGroup).removeAllViews()
        }
        // set the content view to the root of the binding layout
        dialog.setContentView(bottomSheetBinding.root)
        // display the bottom sheet view
        dialog.show()
    }

    /**
     *  Retrieve the status fields, add the fields to a ContingentValueDomain, and set the values to the spinner
     *  When status attribute selected, createFeature() is called.
     */
    private fun setUpStatusAttributes() {
        // get the first field by name
        val statusField = featureTable?.fields?.find { field -> field.name.equals("Status") }
        // get the field's domains as coded value domain
        val codedValueDomain = statusField?.domain as CodedValueDomain
        // get the coded value domain's coded values
        val statusCodedValues = codedValueDomain.codedValues
        // get the selected index if applicable
        val statusNames = mutableListOf<String>()
        statusCodedValues.forEach {
            statusNames.add(it.name)
        }
        // get the items to be added to the spinner adapter
        val adapter = ArrayAdapter(bottomSheetBinding.root.context, R.layout.list_item, statusNames)
        (bottomSheetBinding.statusInputLayout.editText as? AutoCompleteTextView)?.apply {
            setAdapter(adapter)
            setOnItemClickListener { _, _, position, _ ->
                // get the CodedValue of the item selected, and create a feature needed for feature attributes
                createFeature(statusCodedValues[position])
            }
        }
    }

    /**
     * Set up the [feature] using the status attribute's coded value
     * by loading the [featureTable]'s Contingent Value Definition.
     * This function calls setUpProtectionAttributes() once the [feature] has been set
     */
    private fun createFeature(codedValue: CodedValue) {
        // get the contingent values definition from the feature table
        val contingentValueDefinition = featureTable?.contingentValuesDefinition
        if (contingentValueDefinition != null) {
            // load the contingent values definition
            contingentValueDefinition.loadAsync()
            contingentValueDefinition.addDoneLoadingListener {
                // create a feature from the feature table and set the initial attribute
                feature = featureTable?.createFeature() as ArcGISFeature
                feature?.attributes?.set("Status", codedValue.code)
                setUpProtectionAttributes()
            }
        } else {
            val message = "Error retrieving ContingentValuesDefinition from the FeatureTable"
            Toast.makeText(this, message, Toast.LENGTH_SHORT).show()
            Log.e(TAG, message)
        }
    }

    /**
     *  Retrieve the protection attribute fields, add the fields to a ContingentCodedValue, and set the values to the spinner
     *  When status attribute selected, showBufferSeekbar() is called.
     */
    private fun setUpProtectionAttributes() {
        // set the bottom sheet view to enable the Protection attribute, and disable input elsewhere
        bottomSheetBinding.apply {
            protectionInputLayout.isEnabled = true
            bufferSeekBar.isEnabled = false
            bufferSeekBar.value = bufferSeekBar.valueFrom
            protectionInputLayout.editText?.setText("")
            selectedBuffer.text = ""
        }

        // get the contingent value results with the feature for the protection field
        val contingentValuesResult = featureTable?.getContingentValues(feature, "Protection")
        if (contingentValuesResult != null) {
            // get contingent coded values by field group
            // convert the list of ContingentValues to a list of CodedValue
            val protectionCodedValues = mutableListOf<CodedValue>()
            contingentValuesResult.contingentValuesByFieldGroup["ProtectionFieldGroup"]?.forEach { contingentValue ->
                protectionCodedValues.add((contingentValue as ContingentCodedValue).codedValue)
            }
            // set the items to be added to the spinner adapter
            val adapter = ArrayAdapter(
                bottomSheetBinding.root.context,
                R.layout.list_item,
                protectionCodedValues.map { it.name })
            (bottomSheetBinding.protectionInputLayout.editText as? AutoCompleteTextView)?.apply {
                setAdapter(adapter)
                setOnItemClickListener { _, _, position, _ ->
                    // set the protection CodedValue of the item selected, and then enable buffer seekbar
                    feature?.attributes?.set("Protection", protectionCodedValues[position].code)
                    showBufferSeekbar()
                }
            }
        } else {
            val message = "Error loading ContingentValuesResult from the FeatureTable"
            Log.e(TAG, message)
            Toast.makeText(this, message, Toast.LENGTH_SHORT).show()
        }
    }

    /**
     *  Retrieve the buffer attribute fields, add the fields to a ContingentRangeValue,
     *  and set the values to a SeekBar
     */
    private fun showBufferSeekbar() {
        // set the bottom sheet view to enable the buffer attribute
        bottomSheetBinding.apply {
            bufferSeekBar.isEnabled = true
            selectedBuffer.text = ""
        }

        // get the contingent value results using the feature and field
        val contingentValueResult = featureTable?.getContingentValues(feature, "BufferSize")
        val bufferSizeGroupContingentValues =
            (contingentValueResult?.contingentValuesByFieldGroup?.get("BufferSizeFieldGroup")?.get(0) as ContingentRangeValue)
        // set the minimum and maximum possible buffer sizes
        val minValue = bufferSizeGroupContingentValues.minValue as Int
        val maxValue = bufferSizeGroupContingentValues.maxValue as Int
        // check if there can be a max value, if not disable SeekBar & set value to attribute size to 0
        if (maxValue > 0) {
            // get SeekBar instance from the binding layout
            bottomSheetBinding.bufferSeekBar.apply {
                // set the min, max and current value of the SeekBar
                valueFrom = minValue.toFloat()
                valueTo = maxValue.toFloat()
                value = valueFrom
                // set the initial attribute and the text to the min of the ContingentRangeValue
                feature?.attributes?.set("BufferSize", value.toInt())
                bottomSheetBinding.selectedBuffer.text = value.toInt().toString()
                // set the change listener to update the attribute value and the displayed value to the SeekBar position
                addOnChangeListener { _, value, _ ->
                    feature?.attributes?.set("BufferSize", value.toInt())
                    bottomSheetBinding.selectedBuffer.text = value.toInt().toString()
                }
            }
        } else {
            // max value is 0, so disable seekbar and update the attribute value accordingly
            bottomSheetBinding.apply {
                bufferSeekBar.isEnabled = false
                selectedBuffer.text = "0"
            }
            feature?.attributes?.set("BufferSize", 0)
        }
    }

    /**
     * Ensure that the selected values are a valid combination.
     * If contingencies are valid, then display [feature] on the [mapPoint]
     */
    private fun validateContingency(mapPoint: Point) {
        // check if all the features have been set
        if (featureTable == null) {
            val message = "Input all values to add a feature to the map"
            Toast.makeText(this, message, Toast.LENGTH_SHORT).show()
            Log.e(TAG, message)
            return
        }

        try {
            // validate the feature's contingencies
            val contingencyViolations = featureTable?.validateContingencyConstraints(feature)
            if (contingencyViolations?.isEmpty() == true) {
                // if there are no contingency violations in the array,
                // the feature is valid and ready to add to the feature table
                // create a symbol to represent a bird's nest
                val symbol = SimpleMarkerSymbol(SimpleMarkerSymbol.Style.CIRCLE, Color.BLACK, 11F)
                // add the graphic to the graphics overlay
                graphicsOverlay.graphics.add(Graphic(mapPoint, symbol))
                feature?.geometry = mapPoint
                val graphic = feature?.let { createGraphic(it) }
                // add the feature to the feature table
                featureTable?.addFeatureAsync(feature)
                featureTable?.addDoneLoadingListener {
                    // add the graphic to the graphics overlay
                    graphicsOverlay.graphics.add(graphic)
                }
            } else {
                val message = "Invalid contingent values: " + (contingencyViolations?.size?: 0) + " violations found."
                Toast.makeText(this, message, Toast.LENGTH_SHORT).show()
                Log.e(TAG, message)
            }
        } catch (e: Exception) {
            val message = "Invalid contingent values: " + e.message
            Toast.makeText(this, message, Toast.LENGTH_SHORT).show()
            Log.e(TAG, message)
        }
    }

    override fun onPause() {
        mapView.pause()
        super.onPause()
    }

    override fun onResume() {
        super.onResume()
        mapView.resume()
    }

    override fun onDestroy() {
        mapView.dispose()
        // closing the GeoDatabase will commit the transactions made to the temporary ".geodatabase" file
        // then removes the temporary ".geodatabase-wal" and ".geodatabase-shm" files from the cache dir
        geoDatabase?.close()
        super.onDestroy()
    }
}

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