3

8 Best Things for Android Development in 2020

 3 years ago
source link: https://vladsonkin.com/8-best-things-for-android-development-in-2020/?utm_campaign=8-best-things-for-android-development-in-2020
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

2020 is a crazy year for all of us, for sure. But it’s coming to an end, and it’s a perfect time to do a summary of Android development in 2020. In this article, I tried to remember what happened in 2020 in Android development and came up with these 8 main things. #6 is the killer one.

#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.

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.

Kotlin Flow

The Flow has been there for a while, but recently in Kotlin 1.4, we had a significant improvementStateFlow 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: 

MotionLayout Android

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:

class ExampleViewModel @ViewModelInject constructor(
  @Assisted private val savedStateHandle: SavedStateHandle
) : ViewModel() {
  ...
}

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.

jetpack compose declarative ui

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. 

kotlin multiplatform

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

And last but not least is that Android 11 is out there. 

android 11

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.

Android Development 2020 Summary

To sum it up, here are the main 8 things of the Android Development in 2020: View Binding, StateFlow/SharedFlow, MotionLayout, Hilt, DataStore, Compose, and Kotlin Multiplatform.

If you ask me the biggest thing, I would definitely say the Jetpack Compose work from home. And what do you think is the best of 2020 for Android Development? I would love to see your comments below. Happy new year!


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK