private void dispatchMemoryPressure(MemoryPressure level) { // copy listeners array to avoid ConcurrentModificationException if any of the listeners remove // themselves in handleMemoryPressure() MemoryPressureListener[] listeners = mListeners.toArray(new MemoryPressureListener[mListeners.size()]); for (MemoryPressureListener listener : listeners) { listener.handleMemoryPressure(level); } }
/** * Add a listener to be notified of memory pressure events. */ public void addMemoryPressureListener(MemoryPressureListener listener) { mListeners.add(listener); }
/** * Remove a listener previously added with {@link #addMemoryPressureListener}. */ public void removeMemoryPressureListener(MemoryPressureListener listener) { mListeners.remove(listener); }