By: Ivo Van Dongen
Rendering maps at a high frame rate is critical for a smooth user experience. On Android, this is challenging given the broad range of devices in circulation. With our latest release of the Maps SDK for Android, we reworked large parts of our codebase so that you can now use a GLSurfaceView with a dedicated thread for map rendering; this is known as “asynchronous rendering.”
Using separate rendering or “worker” threads frees up the main UI thread so the device can handle intensive processing in the background. The main UI thread can keep running at 60 fps, resulting in smoother map gestures, faster camera animations, and more dynamic data visualizations — a better user experience overall.
GLSurfaceView, unlike TextureView, provides a dedicated drawing surface that is embedded in the View hierarchy. This way, drawing to the surface can be handled by a separate thread, and there is no need to wait for the rest of the UI to be ready to draw.
To start using the GLSurfaceView based maps, simply upgrade to our latest release. No further changes to your code are needed.
TextureView
Although SurfaceView is very efficient, it might not fit all use cases as it creates a separate window and cannot be moved, transformed, or animated. For these situations where you need more flexibility, it’s usually best to use a TextureView. This is less performant than SurfaceView, but it behaves as a standard View and can be manipulated as such.
In previous releases, we’ve included a TextureView backed map to support more dynamic user interfaces, and we’ll continue to do so. With the latest release, the TextureView also uses a dedicated rendering thread, significantly increasing performance.
As before, enable a TextureView instead of the default GLSurfaceView using this layout:
<com.mapbox.mapboxsdk.maps.MapView
...
app:mapbox_renderTextureMode="true"/>
Or in code:
MapboxMapOptions options = new MapboxMapOptions().textureMode(true);
MapView mapView = new MapView(this, options);
Take advantage of these performance upgrades and download our latest Maps SDK for Android. Let us know if you have questions on Twitter, @mapbox.
Asynchronous rendering on Android was originally published in Points of interest on Medium, where people are continuing the conversation by highlighting and responding to this story.