Source:
private void queryRelatedFeatures(final FeatureLayer featureLayer, QueryParameters queryParameters) { final ListenableFuture<FeatureQueryResult> featureQueryResultFuture = featureLayer .selectFeaturesAsync(queryParameters, FeatureLayer.SelectionMode.NEW); featureLayer.clearSelection(); featureQueryResultFuture.addDoneListener(new Runnable() { @Override public void run() { try { if (featureQueryResultFuture.get().iterator().hasNext()) { FeatureQueryResult result = featureQueryResultFuture.get(); for (Feature feature : result) { ArcGISFeature arcGISFeature = (ArcGISFeature) feature; ArcGISFeatureTable selectedTable = (ArcGISFeatureTable) feature.getFeatureTable(); final ListenableFuture<List<RelatedFeatureQueryResult>> relatedFeatureQueryResultFuture = selectedTable .queryRelatedFeaturesAsync(arcGISFeature); relatedFeatureQueryResultFuture.addDoneListener(new Runnable() { @Override public void run() { try { List<RelatedFeatureQueryResult> relatedFeatureQueryResultList = relatedFeatureQueryResultFuture .get(); for (RelatedFeatureQueryResult relatedQueryResult : relatedFeatureQueryResultList) { String relatedTableName = relatedQueryResult.getRelatedTable().getTableName(); mRelatedValues.add(relatedTableName); for (Feature relatedFeature : relatedQueryResult) { ArcGISFeature agsFeature = (ArcGISFeature) relatedFeature; String displayFieldName = agsFeature.getFeatureTable().getLayerInfo().getDisplayFieldName(); String displayFieldValue = agsFeature.getAttributes().get(displayFieldName).toString(); mRelatedValues.add(displayFieldValue); mArrayAdapter.notifyDataSetChanged(); } } } catch (Exception e) { Log.e(TAG, "Exception occurred: " + e.getMessage()); } } }); } } else { mRelatedValues.add(getString(R.string.no_results)); mArrayAdapter.notifyDataSetChanged(); } } catch (Exception e) { Log.e(TAG, "Exception occurred: " + e.getMessage()); } mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED); } }); }

Target:
private void queryRelatedFeatures(final FeatureLayer featureLayer, QueryParameters queryParameters) { final ListenableFuture<FeatureQueryResult> featureQueryResultFuture = featureLayer .selectFeaturesAsync(queryParameters, FeatureLayer.SelectionMode.NEW); featureLayer.clearSelection(); featureQueryResultFuture.addDoneListener(() -> { try { if (featureQueryResultFuture.get().iterator().hasNext()) { FeatureQueryResult result = featureQueryResultFuture.get(); for (Feature feature : result) { ArcGISFeature arcGISFeature = (ArcGISFeature) feature; ArcGISFeatureTable selectedTable = (ArcGISFeatureTable) feature.getFeatureTable(); final ListenableFuture<List<RelatedFeatureQueryResult>> relatedFeatureQueryResultFuture = selectedTable .queryRelatedFeaturesAsync(arcGISFeature); relatedFeatureQueryResultFuture.addDoneListener(() -> { try { List<RelatedFeatureQueryResult> relatedFeatureQueryResultList = relatedFeatureQueryResultFuture .get(); for (RelatedFeatureQueryResult relatedQueryResult : relatedFeatureQueryResultList) { String relatedTableName = relatedQueryResult.getRelatedTable().getTableName(); mRelatedValues.add(relatedTableName); for (Feature relatedFeature : relatedQueryResult) { ArcGISFeature agsFeature = (ArcGISFeature) relatedFeature; String displayFieldName = agsFeature.getFeatureTable().getLayerInfo().getDisplayFieldName(); String displayFieldValue = agsFeature.getAttributes().get(displayFieldName).toString(); mRelatedValues.add(displayFieldValue); mArrayAdapter.notifyDataSetChanged(); } } } catch (InterruptedException | ExecutionException e) { String error = "Error getting related feature query result: " + e.getMessage(); Toast.makeText(this, error, Toast.LENGTH_LONG).show(); Log.e(TAG, error); } }); } } else { mRelatedValues.add(getString(R.string.no_results)); mArrayAdapter.notifyDataSetChanged(); } } catch (InterruptedException | ExecutionException e) { String error = "Error getting feature query result: " + e.getMessage(); Toast.makeText(this, error, Toast.LENGTH_LONG).show(); Log.e(TAG, error); } mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED); }); }