GIF App Development – Challenges & Tips
In past years, GIFs have managed to become quite popular. These GIFs are usually a perfect way to respond to a funny message you have received or to express some other kind of emotion thru a message. They now pervade everything from popular culture to ad campaigns. For the next-gen of designers and developers, knowing your way around motion graphics and having a good knowledge of the basics of creating a GIF is important. In this article, we’ll discuss GIFs app development on the Android platform. It’s worth knowing what challenges you can expect during GIF app development, and how to handle them.
Why Android doesn’t support GIFs natively?
Since the beginning, GIF app support on Android was never perfect, up to Android 8 the system itself used to support only non-animated GIFs displaying and without encoding support.
Starting from Android 9, Image Decoder exists and this can produce GIF Image Drawables. However, these classes are only part of the platform and aren’t backported to AndroidX Jetpack, now (June 2020), only about 40 percent of users can benefit from them.
Why GIF support is so complicated on Android?
Initially, it is much more problematic to develop displaying an animated image, than the static image. Next, encoding is more complicated than decoding so we have difficulty in both.
Static vs animations images
The main differences between static images are PNG or JPG files, and animations are GIF files, but GIFs can also be not animated.
Static image decoding usually taking inputs from a local file or image URL and producing output like a bitmap 2D array of pixels. After, everything is up to the UI layer, and the decoder does not require to care about that. Note that we are considering the simple case now displaying an image as is.
Animation can be defined as an order of static images
The decoding process contains multiple aforementioned steps. But there are more factors to consider. Initially, we require some kind of a ticker or clock that is responsible for advancing the time means that switching to subsequent frames.
Such a ticker needs to be aware of the UI lifecycle. Especially it needs to be disposed of when UI is no longer alive for instance user pressed the back button or simply navigate to another app. Handling the Android UI lifecycle properly is a significant challenge for developers to build it. In Android applications, a lot of bugs and crashes are caused by leaks which are effects of improper lifecycle handling. Especially the Movie class used recently for GIF decoding also used to leak. After 60 days another one was exposed.
Encoding vs decoding
GIF encoding process is much more complicated than decoding. There are two main reasons. Image data in the GIF file is separated into multiple frames. But, they are not always the same as physical film frames. Let’s take a look at the below animation:
1. The most effective way of encoding is to store only differences of subsequent frames:
2. Of course, nothing prohibits from saving the full-sized second frame like this: