Skip to content

Commit d30f412

Browse files
committed
Cancel timer updating devices when editor is closed
1 parent 7d6712f commit d30f412

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/processing/mode/android/AndroidEditor.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
public class AndroidEditor extends JavaEditor {
5353
private AndroidMode androidMode;
5454

55+
private java.util.Timer updateDevicesTimer;
56+
5557
protected AndroidEditor(Base base, String path, EditorState state,
5658
Mode mode) throws EditorException {
5759
super(base, path, state, mode);
@@ -232,9 +234,14 @@ public void actionPerformed(ActionEvent e) {
232234
menu.add(deviceMenu);
233235

234236
// start updating device menus
237+
// TODO: each Editor now runs its own, might be better to move this to Mode
235238
UpdateDeviceListTask task = new UpdateDeviceListTask(deviceMenu);
236-
java.util.Timer timer = new java.util.Timer();
237-
timer.schedule(task, 5000, 5000);
239+
if (updateDevicesTimer == null) {
240+
updateDevicesTimer = new java.util.Timer();
241+
} else {
242+
updateDevicesTimer.cancel();
243+
}
244+
updateDevicesTimer.schedule(task, 5000, 5000);
238245

239246
menu.addSeparator();
240247

@@ -468,6 +475,14 @@ public void showReference(String filename) {
468475
// }
469476

470477

478+
@Override
479+
public void dispose() {
480+
if (updateDevicesTimer != null) {
481+
updateDevicesTimer.cancel();
482+
}
483+
super.dispose();
484+
}
485+
471486
public void statusError(String what) {
472487
super.statusError(what);
473488
// new Exception("deactivating RUN").printStackTrace();

0 commit comments

Comments
 (0)