diff options
author | Bilal Alsharifi <bilal.alsharifi@gmail.com> | 2021-01-13 17:11:48 -0500 |
---|---|---|
committer | Bilal Alsharifi <bilal.alsharifi@gmail.com> | 2021-01-13 17:11:48 -0500 |
commit | f7e67a08d21d0f382ada1e897c1b284ec8d2e1e4 (patch) | |
tree | 5e8671579781d3a7c09f3c3a2735ca97b3cef4fb | |
parent | ed37e7240b4acf935f51a274d2c57b05eed3060d (diff) | |
download | sdl_android-f7e67a08d21d0f382ada1e897c1b284ec8d2e1e4.tar.gz |
Use ScheduledExecutorService in SdlRemoteDisplay
-rw-r--r-- | android/sdl_android/src/main/java/com/smartdevicelink/streaming/video/SdlRemoteDisplay.java | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/streaming/video/SdlRemoteDisplay.java b/android/sdl_android/src/main/java/com/smartdevicelink/streaming/video/SdlRemoteDisplay.java index f704bf769..c5fccf545 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/streaming/video/SdlRemoteDisplay.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/streaming/video/SdlRemoteDisplay.java @@ -49,6 +49,10 @@ import com.smartdevicelink.util.DebugTool; import java.lang.reflect.Constructor; import java.util.concurrent.Callable; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.TimeUnit; /** * SdlRemoteDisplay is an abstract class that should be extended by developers to create their remote displays. @@ -64,7 +68,8 @@ public abstract class SdlRemoteDisplay extends Presentation { protected Window w; protected View mainView; - protected final Handler handler = new Handler(); + protected final ScheduledExecutorService executor = Executors.newScheduledThreadPool(1); + protected ScheduledFuture<?> refreshTaskScheduledFuture; protected final Handler uiHandler = new Handler(Looper.getMainLooper()); protected Callback callback; @@ -88,11 +93,13 @@ public abstract class SdlRemoteDisplay extends Presentation { } protected void startRefreshTask() { - handler.postDelayed(mStartRefreshTaskCallback, REFRESH_RATE_MS); + refreshTaskScheduledFuture = executor.scheduleAtFixedRate(mStartRefreshTaskCallback, 0, REFRESH_RATE_MS, TimeUnit.MILLISECONDS); } protected void stopRefreshTask() { - handler.removeCallbacks(mStartRefreshTaskCallback); + if (refreshTaskScheduledFuture != null) { + refreshTaskScheduledFuture.cancel(false); + } } protected final Runnable mStartRefreshTaskCallback = new Runnable() { @@ -103,8 +110,6 @@ public abstract class SdlRemoteDisplay extends Presentation { if (mainView != null) { mainView.invalidate(); } - - handler.postDelayed(this, REFRESH_RATE_MS); } }; |