Add an animated gif to your Android splash screen
If you are using the Navigation component, you might have the need for separate flows. Conditional navigation is not so bad but we want to follow the principles of the library which lists a fixed starting destination right away.
A splash screen is a nice option to add some fun to your app while providing this landing page. An animated gif makes it so much more interesting and is easy to do with the advent of AnimatedImageDrawable.
A simple recipe for it from a Fragment using coroutines is as follows:
Notice line 3: always structure your coroutines to live within the scope of the calling class.
Using withContext() we can get to the background for heavy operations like decoding and switch back to the main thread to update the UI.