2020 is a crazy year for all of us, for sure. In this article, I tried to remember what happened in 2020 in Android development and came up with these 10 main things. #6 is the important one.
Refer - https://vladsonkin.com/
#1 View Binding
View Binding makes our work with views easier, and it brings advantages over the standard findViewById()
and other alternative solutions. View Binding generates a binding class for each XML layout, and the instance contains references to all the views with the ID.
Column 1 | ButterKnife | Kotlin Synthetics | Data Binding | findViewById | View Binding |
---|---|---|---|---|---|
Fast | * | * | |||
Null-safe | |||||
Compile-time safe | ** |
View Binding takes the best parts of the other solutions and avoids their drawbacks. And it’s more important now since the popular Kotlin Synthetics are deprecated in Kotlin 1.4.
#2 StateFlow and SharedFlow
Kotlin Flow is a stream of data that can be computed asynchronously. For example, we can make a network request with the Flow and then handle it without blocking the main thread.
The Flow has been there for a while, but recently in Kotlin 1.4, we had a significant improvement – StateFlow and SharedFlow. In a few words, they provide us state management and effectively replace the ConflatedBroadcastChannel and BroadcastChannel (they are deprecated).
No need to use RxJava or channels because the Flow can cover everything. More than that, some blogs already advise replacing the LiveData with the StateFlow/SharedFlow.
#3 MotionLayout
MotionLayout is a new animation tool, and it’s a part of ConstraintLayout 2.0. With MotionLayout, you can animate pretty much everything:
We can move elements, rotate, fade, scale them, and even animate custom attributes. In addition to that, starting with Android Studio 4.0, we have a special editor for the MotionLayout. With this, we can create animations easier and preview them.
To learn more about MotionLayout, check the codelab and samples on GitHub.
#4 Hilt
Hilt now is a new recommended DI for Android from Google. If you used a Dagger in your project, then you know how much boilerplate you need to write and how the overall architecture is complicated.
That’s precisely why the Hilt was introduced, to simplify the structure and make the DI setup an easy thing thanks to a standard set of components and scopes.
The Hilt is also well integrated with the Jetpack Components: ViewModel, Navigation, WorkManager. Use the @ViewModelInject
annotation in the ViewModel object’s constructor, annotate the SavedStateHandle dependency with @Assisted
, and you’re set. No more Factory is needed:
Check out this official guide for more information and try it in the codelab.
#5 Jetpack Datastore
Android DataStore is a new way of storing the data, and it aims to replace the SharedPreferences. Jetpack DataStore is built on top of Kotlin Coroutines and Flow, and it allows us to store the data in key-value pairs (the same as SharedPreferences) or typed objects (backed by Protocol Buffers).
It brings great benefits over the “old” SharedPreferences, namely:
- Async API for storing and reading the data (Flow)
- Type-safety out of the box (Protocol Buffers)
- Safe to call from UI thread (Dispatchers.IO underneath)
And many other perks, such as transactional API, which guarantee consistency. Jetpack DataStore is an official recommendation, and the migration from the SharedPreferences is an easy one with 3 steps.
#6 Jetpack Compose
We all know that Jetpack Compose is the most significant trend of 2020 and upcoming years. This library is a new way to create UI, which replaces the current one with XML layouts and Views. Jetpack Compose mainly has 2 benefits:
Declarative paradigm
The declarative approach simplifies work with the views and decreases the possible errors by regenerating the entire screen from scratch. Do you want to update an element? Then you need to update the state and composite the screen again. And don’t worry about performance; Compose will only update the element that needs to be changed. No need to manually change the view hierarchy.
Standalone library
Jetpack Compose doesn’t rely on an operation system, and because of it has great flexibility. Now the UI is not tied to the Android OS version, and the users can receive the latest features/updates no matter what Android version they have.
Less XML and more Kotlin. How cool is that
Jetpack Compose is still in alpha and not ready for production. But you already can make your hands dirty by following the official tutorial, and playing with the great samples on GitHub.
Another great news is that recently Jetpack Compose became available for the desktop. Now you can share your UI with the Android apps. And you can share your business logic too with the help of Kotlin Multiplatform.
#7 Kotlin Multiplatform
Kotlin Multiplatform Mobile gives us the ability to write the business logic once in Kotlin and then reuse it in Android and iOS apps. Beautiful idea, we create the module with the business logic and then use it in our mobile apps.
What I especially like is that introducing the Kotlin Multiplatform to our projects is a low-risk. We can start step by step by creating a small feature first and then reuse it.
It’s also quite different from cross-platform; we just share the business logic and leave the UI work for the native apps. However, if we use the Jetpack Compose for UI, we can already have a desktop and Android app by reusing almost the whole codebase.
You can play with Kotlin multiplatform in this tutorial.
#8 Android 11
Next is Android 11 is out there.
This version was mostly about privacy and introduced such features as Scoped Storage, Package Visibility, and other enhancements.
Check out this article on how to prepare your app for Android 11.
#9 Firebase Firestore
Cloud Firestore is a flexible, scalable database for mobile, web, and server development from Firebase and Google Cloud.
#10 CameraX Features
CameraX is a Jetpack support library, built to help you make camera app development easier. It provides a consistent and easy-to-use API surface that works across most Android devices, with backward-compatibility to Android 5.0 (API level 21).
Thanks for reading, Please hit like if you see these :) Happy new year. Happy Coding.
Comments
Post a Comment