Source:
void analyzeHotspots(final String from, final String to) { if (mGeoprocessingJob != null) { mGeoprocessingJob.cancel(); } mMapView.getMap().getOperationalLayers().remove(mHotspotMapImageLayer); mCancelled = false; final ListenableFuture<GeoprocessingParameters> paramsFuture = mGeoprocessingTask.createDefaultParametersAsync(); paramsFuture.addDoneListener(() -> { try { GeoprocessingParameters geoprocessingParameters = paramsFuture.get(); geoprocessingParameters.setProcessSpatialReference(mMapView.getSpatialReference()); geoprocessingParameters.setOutputSpatialReference(mMapView.getSpatialReference()); String queryString = String.format(QUERY_INPUT_STRING, from, to); geoprocessingParameters.getInputs().put("Query", new GeoprocessingString(queryString)); Log.i(TAG, "Query: " + queryString.toString()); mGeoprocessingJob = mGeoprocessingTask.createJob(geoprocessingParameters); mGeoprocessingJob.start(); showProgressDialogFragment(); mGeoprocessingJob.addProgressChangedListener(() -> { if (findProgressDialogFragment() != null) { findProgressDialogFragment().setProgress(mGeoprocessingJob.getProgress()); Log.d(TAG, "Updating progress: " + mGeoprocessingJob.getProgress()); } }); mGeoprocessingJob.addJobDoneListener(() -> { if (mGeoprocessingJob.getStatus() == Job.Status.SUCCEEDED) { Log.i(TAG, "Job succeeded."); GeoprocessingResult geoprocessingResult = mGeoprocessingJob.getResult(); mHotspotMapImageLayer = geoprocessingResult.getMapImageLayer(); addLayerToMapView(mHotspotMapImageLayer, mMapView); } else if (mCancelled) { Toast.makeText(MainActivity.this, "Job canceled.", Toast.LENGTH_SHORT).show(); Log.i(TAG, "Job cancelled."); } else { Log.e(TAG, "Job did not succeed!"); Toast.makeText(MainActivity.this, "Job did not succeed", Toast.LENGTH_LONG).show(); } if (findProgressDialogFragment() != null) { findProgressDialogFragment().dismiss(); } }); } catch (InterruptedException | ExecutionException e) { e.printStackTrace(); } }); }

Target:
private void analyzeHotspots(final String from, final String to) { if (mGeoprocessingJob != null) { mGeoprocessingJob.cancel(); } mMapView.getMap().getOperationalLayers().remove(mHotspotMapImageLayer); mCancelled = false; final ListenableFuture<GeoprocessingParameters> paramsFuture = mGeoprocessingTask.createDefaultParametersAsync(); paramsFuture.addDoneListener(() -> { try { GeoprocessingParameters geoprocessingParameters = paramsFuture.get(); geoprocessingParameters.setProcessSpatialReference(mMapView.getSpatialReference()); geoprocessingParameters.setOutputSpatialReference(mMapView.getSpatialReference()); String queryString = String.format(QUERY_INPUT_STRING, from, to); geoprocessingParameters.getInputs().put("Query", new GeoprocessingString(queryString)); Log.i(TAG, "Query: " + queryString); mGeoprocessingJob = mGeoprocessingTask.createJob(geoprocessingParameters); mGeoprocessingJob.start(); showProgressDialogFragment(); mGeoprocessingJob.addProgressChangedListener(() -> { if (findProgressDialogFragment() != null) { findProgressDialogFragment().setProgress(mGeoprocessingJob.getProgress()); } }); mGeoprocessingJob.addJobDoneListener(() -> { if (mGeoprocessingJob.getStatus() == Job.Status.SUCCEEDED) { Log.i(TAG, "Job succeeded."); GeoprocessingResult geoprocessingResult = mGeoprocessingJob.getResult(); mHotspotMapImageLayer = geoprocessingResult.getMapImageLayer(); addLayerToMapView(mHotspotMapImageLayer, mMapView); } else if (mCancelled) { Toast.makeText(MainActivity.this, "Job canceled.", Toast.LENGTH_SHORT).show(); Log.i(TAG, "Job cancelled."); } else { String error = mGeoprocessingJob.getError().getMessage(); Toast.makeText(MainActivity.this, "Job did not succeed! " + error, Toast.LENGTH_LONG).show(); Log.e(TAG, "Job did not succeed! " + error); } if (findProgressDialogFragment() != null) { findProgressDialogFragment().dismiss(); } }); } catch (InterruptedException | ExecutionException e) { String error = e.getMessage(); Toast.makeText(MainActivity.this, "Geoprocessing job failed " + error, Toast.LENGTH_LONG).show(); Log.e(TAG, "Geoprocessing job failed " + error); } }); }