From a0127111f56cc562f8321ddb42a22679583b26a4 Mon Sep 17 00:00:00 2001 From: PavelRatushnyi Date: Thu, 26 Oct 2017 11:12:21 +0300 Subject: [PATCH 1/3] Fix async task --- OsmAnd/src/net/osmand/plus/CurrentPositionHelper.java | 2 +- .../core/samples/android/sample1/CurrentPositionHelper.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/CurrentPositionHelper.java b/OsmAnd/src/net/osmand/plus/CurrentPositionHelper.java index a811f068ec..190b4b6ebe 100644 --- a/OsmAnd/src/net/osmand/plus/CurrentPositionHelper.java +++ b/OsmAnd/src/net/osmand/plus/CurrentPositionHelper.java @@ -99,7 +99,7 @@ public class CurrentPositionHelper { } return null; } - }.execute((Void) null); + }.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR, (Void) null); res = true; } return res; diff --git a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/CurrentPositionHelper.java b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/CurrentPositionHelper.java index 984c69fe6c..79b70288d2 100644 --- a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/CurrentPositionHelper.java +++ b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/CurrentPositionHelper.java @@ -103,7 +103,7 @@ public class CurrentPositionHelper { } return null; } - }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null); + }.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR, (Void) null); res = true; } return res; From a728d8fdcbb1395546cc194c38661bf26cbccd51 Mon Sep 17 00:00:00 2001 From: PavelRatushnyi Date: Thu, 26 Oct 2017 11:29:46 +0300 Subject: [PATCH 2/3] Fix async tasks --- OsmAnd/src/net/osmand/plus/activities/MapActivity.java | 2 +- OsmAnd/src/net/osmand/plus/download/DownloadActivity.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 7bc3921d6e..d38c434ebc 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -1234,7 +1234,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven protected void onPostExecute(Void result) { } - }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null); + }.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR, (Void) null); } diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java b/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java index c11773f884..16445af8e0 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java @@ -784,7 +784,7 @@ public class DownloadActivity extends AbstractDownloadActivity implements Downlo newDownloadIndexes(); } }; - task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + task.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR); } From 64c6f5836eeae883c8eeb6bb924ee9304b2a93c7 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Thu, 26 Oct 2017 13:40:30 +0300 Subject: [PATCH 3/3] Create executors --- OsmAnd/src/net/osmand/plus/CurrentPositionHelper.java | 5 ++++- OsmAnd/src/net/osmand/plus/activities/MapActivity.java | 6 +++++- OsmAnd/src/net/osmand/plus/download/DownloadActivity.java | 6 +++++- .../core/samples/android/sample1/CurrentPositionHelper.java | 5 ++++- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/CurrentPositionHelper.java b/OsmAnd/src/net/osmand/plus/CurrentPositionHelper.java index 190b4b6ebe..e465cc6b5b 100644 --- a/OsmAnd/src/net/osmand/plus/CurrentPositionHelper.java +++ b/OsmAnd/src/net/osmand/plus/CurrentPositionHelper.java @@ -25,6 +25,8 @@ import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; public class CurrentPositionHelper { @@ -36,6 +38,7 @@ public class CurrentPositionHelper { private ApplicationMode am; private List usedReaders = new ArrayList<>(); private static final org.apache.commons.logging.Log log = PlatformUtil.getLog(CurrentPositionHelper.class); + private ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor(); public CurrentPositionHelper(OsmandApplication app) { this.app = app; @@ -99,7 +102,7 @@ public class CurrentPositionHelper { } return null; } - }.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR, (Void) null); + }.executeOnExecutor(singleThreadExecutor, (Void) null); res = true; } return res; diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index d38c434ebc..d9956f280e 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -136,6 +136,8 @@ import java.util.List; import java.util.Map; import java.util.Timer; import java.util.TimerTask; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -200,6 +202,8 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven private InAppHelper inAppHelper; private Timer splashScreenTimer; + private ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor(); + @Override public void onCreate(Bundle savedInstanceState) { setRequestedOrientation(AndroidUiHelper.getScreenOrientation(this)); @@ -1234,7 +1238,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven protected void onPostExecute(Void result) { } - }.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR, (Void) null); + }.executeOnExecutor(singleThreadExecutor, (Void) null); } diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java b/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java index 16445af8e0..f20145a8f1 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java @@ -78,6 +78,8 @@ import java.util.HashSet; import java.util.List; import java.util.Locale; import java.util.Set; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import static net.osmand.plus.OsmandApplication.SHOW_PLUS_VERSION_INAPP_PARAM; @@ -125,6 +127,8 @@ public class DownloadActivity extends AbstractDownloadActivity implements Downlo private boolean nauticalPluginDisabled; private boolean freeVersion; + private ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor(); + @Override protected void onCreate(Bundle savedInstanceState) { getMyApplication().applyTheme(this); @@ -784,7 +788,7 @@ public class DownloadActivity extends AbstractDownloadActivity implements Downlo newDownloadIndexes(); } }; - task.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR); + task.executeOnExecutor(singleThreadExecutor); } diff --git a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/CurrentPositionHelper.java b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/CurrentPositionHelper.java index 79b70288d2..07f06e06ef 100644 --- a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/CurrentPositionHelper.java +++ b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/CurrentPositionHelper.java @@ -23,6 +23,8 @@ import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; public class CurrentPositionHelper { @@ -33,6 +35,7 @@ public class CurrentPositionHelper { private List readers = new ArrayList<>(); private List usedReaders = new ArrayList<>(); private static final org.apache.commons.logging.Log log = PlatformUtil.getLog(CurrentPositionHelper.class); + private ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor(); public CurrentPositionHelper(SampleApplication app) { this.app = app; @@ -103,7 +106,7 @@ public class CurrentPositionHelper { } return null; } - }.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR, (Void) null); + }.executeOnExecutor(singleThreadExecutor, (Void) null); res = true; } return res;