From 1daffd4af5de0ec3f724d673297e1d4acc189b67 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Fri, 7 Sep 2018 09:36:38 +0200 Subject: [PATCH] Fix ConcurrentModificationException --- .../ui/asynctasks/SafeAsyncTasksManager.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/communiquons/android/comunic/client/ui/asynctasks/SafeAsyncTasksManager.java b/app/src/main/java/org/communiquons/android/comunic/client/ui/asynctasks/SafeAsyncTasksManager.java index e7b14f0..9319fce 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/ui/asynctasks/SafeAsyncTasksManager.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/ui/asynctasks/SafeAsyncTasksManager.java @@ -99,10 +99,18 @@ public class SafeAsyncTasksManager { * @param cls The tasks to disable */ public void unsetSpecificTasks(Class cls){ - for (SafeAsyncTask task : mTasks){ - if(task.getClass().equals(cls)) - unsetTask(task); + ArrayList toRemove = new ArrayList<>(); + for(int i = 0; i < mTasks.size(); i++){ + if(mTasks.get(i).getClass().equals(cls)) + toRemove.add(mTasks.get(i)); } + + while (toRemove.size() > 0){ + SafeAsyncTask task = toRemove.get(toRemove.size() - 1); + unsetTask(task); + toRemove.remove(task); + } + } }