AnimationThreadController

object AnimationThreadController

Experimental controller singleton allowing to use background thread for all Mapbox animations. Most likely should not be used directly, calling useBackgroundThread should do all the work.

By default all Mapbox animations are running on Android Main thread.

Following Mapbox plugins are updated to make use of background animation thread:

  • plugin-locationcomponent

  • plugin-animation

  • plugin-viewport

Switching between useBackgroundThread and useMainThread could be done at any point in runtime.

Using this class is extremely unsafe and error prone, it should be used in very specific use-cases! Even when it's essential to use it (for example Android Auto use-case on specific devices when locking the device) it would be safer to use Android Main thread as much as possible and switch to background thread only when it's needed.

Functions

postOnAnimatorThread
Link copied to clipboard
fun postOnAnimatorThread(function: () -> Unit)

Execute function on animator thread.

postOnMainThread
Link copied to clipboard
fun postOnMainThread(function: () -> Unit)

Execute function on Android Main thread.

useBackgroundThread
Link copied to clipboard
fun useBackgroundThread()

Spawn new animation HandlerThread that will be used for all Mapbox animators. If animation thread is already running - function is no-op.

useMainThread
Link copied to clipboard
fun useMainThread()

If useBackgroundThread was called beforehand - kill background animator thread and use Android Main thread for all Mapbox animators. Otherwise function is no-op.

Properties

usingBackgroundThread
Link copied to clipboard
var usingBackgroundThread: Boolean = false

Indicates if background thread is used now to run Mapbox animators.