Browse Source

Fixed crash when unregistering EventBus subsribers

closes #291
Guy Carmeli 8 years ago
parent
commit
653b0716ff

+ 4
- 1
android/app/src/main/java/com/reactnativenavigation/events/EventBus.java View File

3
 import java.lang.ref.WeakReference;
3
 import java.lang.ref.WeakReference;
4
 import java.util.ArrayList;
4
 import java.util.ArrayList;
5
 import java.util.List;
5
 import java.util.List;
6
+import java.util.ListIterator;
6
 
7
 
7
 public enum EventBus {
8
 public enum EventBus {
8
     instance;
9
     instance;
15
     }
16
     }
16
 
17
 
17
     public void unregister(Subscriber subscriber) {
18
     public void unregister(Subscriber subscriber) {
18
-        for (WeakReference<Subscriber> ref : subscribers) {
19
+        ListIterator<WeakReference<Subscriber>> iterator = subscribers.listIterator();
20
+        while (iterator.hasNext()) {
21
+            WeakReference<Subscriber> ref = iterator.next();
19
             Subscriber registered = ref.get();
22
             Subscriber registered = ref.get();
20
             if (registered != null && registered == subscriber) {
23
             if (registered != null && registered == subscriber) {
21
                 subscribers.remove(ref);
24
                 subscribers.remove(ref);