aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching
diff options
context:
space:
mode:
authorrsudev <rasch@munin-soft.de>2014-06-25 23:06:56 +0200
committerrsudev <rasch@munin-soft.de>2014-06-25 23:06:56 +0200
commit32108e31a0222b8e5228754fda3605f2e028f9f3 (patch)
treec6fdd7355f90b12125c99a3948c5d09b8ff9ae12 /main/src/cgeo/geocaching
parent386715b13fd1cde56ec034a3e612cad7e6fd45ab (diff)
downloadcgeo-32108e31a0222b8e5228754fda3605f2e028f9f3.zip
cgeo-32108e31a0222b8e5228754fda3605f2e028f9f3.tar.gz
cgeo-32108e31a0222b8e5228754fda3605f2e028f9f3.tar.bz2
Fixes #4001, ANR on map
- fixed leaking rx threads by re-using the LoadTimer worker
Diffstat (limited to 'main/src/cgeo/geocaching')
-rw-r--r--main/src/cgeo/geocaching/maps/CGeoMap.java20
1 files changed, 16 insertions, 4 deletions
diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java
index 9a3f713..4524dec 100644
--- a/main/src/cgeo/geocaching/maps/CGeoMap.java
+++ b/main/src/cgeo/geocaching/maps/CGeoMap.java
@@ -45,6 +45,7 @@ import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
+import rx.Scheduler;
import rx.Subscription;
import rx.functions.Action0;
import rx.functions.Action1;
@@ -1087,10 +1088,13 @@ public class CGeoMap extends AbstractMap implements ViewFactory {
private volatile boolean isUnsubscribed = false;
+ private Scheduler.Worker worker;
+
@NonNull private final WeakReference<CGeoMap> mapRef;
- public LoadTimerAction(@NonNull final CGeoMap map) {
+ public LoadTimerAction(@NonNull final CGeoMap map, final Scheduler.Worker worker) {
this.mapRef = new WeakReference<CGeoMap>(map);
+ this.worker = worker;
}
@Override
@@ -1136,13 +1140,20 @@ public class CGeoMap extends AbstractMap implements ViewFactory {
}
if (!isUnsubscribed) {
- Schedulers.newThread().createWorker().schedule(this, 250, TimeUnit.MILLISECONDS);
+ if (worker == null) {
+ worker = Schedulers.newThread().createWorker();
+ }
+ worker.schedule(this, 250, TimeUnit.MILLISECONDS);
}
}
@Override
public void unsubscribe() {
isUnsubscribed = true;
+ if (worker != null) {
+ worker.unsubscribe();
+ worker = null;
+ }
}
@Override
@@ -1158,8 +1169,9 @@ public class CGeoMap extends AbstractMap implements ViewFactory {
// We cannot use schedulePeriodically with RxJava 0.19 and earlier because the unsubscription
// mechanism fails. As a consequence, we reschedule periodically by hand as long as we are not
// unsubscribed. There may be a small drift, but it has no consequence.
- final LoadTimerAction action = new LoadTimerAction(this);
- Schedulers.newThread().createWorker().schedule(action, 250, TimeUnit.MILLISECONDS);
+ final Scheduler.Worker worker = Schedulers.newThread().createWorker();
+ final LoadTimerAction action = new LoadTimerAction(this, worker);
+ worker.schedule(action, 250, TimeUnit.MILLISECONDS);
return action;
}