Following on from this discussion:
Android AsyncTask API deprecating in Android 11.What are the alternatives?
I need a method for storing values inside the Task Runner. For example, if I am adding values to a list, they will only exist within the task runner and then somehow disappear at the end of the task. Is there a way to permanently store values. I am using the exact same class as the thread above:
TaskRunner taskRunner3 = new TaskRunner();
taskRunner3.executeAsync(new TaskRequest(elevationURL), (data3) -> {
TaskRunner taskRunner4 = new TaskRunner();
taskRunner4.executeAsync(new ElevationTaskParser(data3), (data4) -> {
LatLng prev = null;
List<LatLng> pointsToAlertAt = new ArrayList<>();
double gradient;
boolean previousLess = true;
for (LatLng curr : data4.keySet()) {
PolylineOptions polylineOptions = new PolylineOptions();
if (prev == null) {
prev = curr;
continue;
}
gradient = calculateGradient(data4.get(prev), data4.get(curr));
if (gradient > ELEVATION_ALERT_VALUE && previousLess) {
previousLess = false;
pointsToAlertAt.add(curr);
} else if (gradient <= ELEVATION_ALERT_VALUE) {
previousLess = true;
}
In the code above, pointsToAlert is the list that I want to make as a private field of my activity class, but its items become null at the end of the task. Thanks for having a look!