Along with the coroutine adoption,
StateFlowbecomes an alternative observable data holder for
StateFlowhas almost all the functionalities of
LiveDatawithout the main thread confinment. On top of following the best practice of the safer way to collect flows from Android UI, this story covers another common pitfall in detail.
Android KTX provides opinionated methods facilitating using Kotlin Coroutines in Android Architecture Components. For instance,
Flow<T>.asLiveData() is quite helpful to migrate your apps using LiveData towards coroutine. Make sure to understand their behaviors underneath before using them!
This story is a continuation of the previous one.
Have you ever got frustrated to debug LiveData changes by adding numerous log statements or breakpoints? As the core data structure of Android Architecture Components, LiveData is used widely in many apps to hold observable data. However, its debugging experience could still be a pain point after these many years.
Android KTX provides opinionated methods, such as
Flow<T>.asLiveData(), facilitating using Kotlin Coroutines in Android Architecture Components. Make sure to understand their behaviors underneath before using them!
The official documentation on Kotlin coroutines on Android is quitewell-written, while there are numerous article posts covering the basics. In this story, we will focus…
If generic types are exposed in Kotlin API, consider
@JvmSuppressWildcards so that your Java consumer can compile successfully.
Kotlin generics are different from (in my opinion, smarter than) Java generics. Kotlin generics has declaration-site variance and type projections, which are officially documented here. Generics is a gigantic topic itself. …
A simple trick to write an email report for your readers
Recently my team wrote an email report to the leadership team on the executive summary of Android Gradle Plugin upgrades. Below is the initial version of the reports in the exec summary section:
- We have migrated to Android…
MockK is a mocking library written in Kotlin and for Kotlin. In addition to the traditional functionality provided by JVM based mocking libraries, Kotlin’s language feature significantly improves MockK’s usability.
However, aside from MockK, have you…
Reporting a bug outside your company’s codebase is not as simple as DMing your colleague. This story listed do’s and don’ts for submitting bug reports, from the perspective of an Android engineer.
I have been working in the infrastructure team to support the feature development teams at my company for…
Kotlin 1.4 introduced an exciting new feature called Explicit API mode. In this new mode, libraries need to provide explicit visibility modifiers and explicit return types. Library authors can then be free from future regret in case they accidentally expose APIs to their dependents.
While applying the explicit API mode…
If a generic container type is written in Java (such as LiveData<T>), it has to be used safely xor elegantly.
To use it safely and elegantly, declare the type in Kotlin.