Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon

Airbnb introduces MvRx, a new Android framework for easier, faster, and high-quality product development

Save for later
  • 3 min read
  • 29 Aug 2018

article-image

Yesterday, Airbnb open sourced MvRx (pronounced mavericks), their Android architecture. MvRx received an astounding adoption rate when it was first introduced to the engineers at Airbnb in July. Later, it became their standard way of writing screens and now it is used for nearly all of their product development. Due to its popularity among Airbnb’s app developers, they have decided to share it with all Android developers.

MvRx is based on Kotlin, which helped MvRx’s developers to leverage several powerful features provided by the language to build a cleaner API. It is built on top of the following technologies and concepts:

  • Kotlin
  • Android Architecture Components
  • RxJava
  • React (conceptually)
  • Epoxy (optional but recommended)

Why you should use MvRx?


Using MvRx you will be able to write simple and complex Android screens easily. MvRx also helps making certain tasks easier and faster for Android app developers such as:

  1. Saving view state and business logic in onSaveInstanceState properly
  2. Creating layouts with a toolbar, RecyclerView, and footer over and over again
  3. Executing the onSuccess and onFailure handlers for asynchronous requests
  4. Dealing with the Android lifecycle

Unlock access to the largest independent learning library in Tech for FREE!
Get unlimited access to 7500+ expert-authored eBooks and video courses covering every tech area you can think of.
Renews at $19.99/month. Cancel anytime

What are its core concepts?

  • State: MvRxState is an interface that you need to extend with an immutable Kotlin data class. It contains the properties necessary to render your screen.
  • ViewModel: All the business logic and anything other than just rendering views is handled by MvRxViewModels. It extends Google's ViewModel. The following lifecycle diagram clearly illustrates how ViewModels simplify lifecycles on Android:


airbnb-introduces-mvrx-a-new-android-framework-for-easier-faster-and-high-quality-product-development-img-0

Source: GitHub


  • View: MvRxView is a simple interface that users see and interact with. It is a LifecycleOwner consisting of a invalidate() function that gets called any time there is a change in the state of its ViewModels.
  • Async: MvRx makes handling async requests like fetching from a network or a database easier using Async. It is a Kotlin sealed class with four types: Uninitialized, Loading, Success, and Fail. MvRx provides an extension to map Observable<T> to an Async<T> property on your state to make executing network requests and other actions easy with a single line of code.

How can you install it?


To use MvRx, you need to add the following dependency to your project in the build.gradle file:

dependencies {

 implementation 'com.airbnb.android:mvrx:0.5.0'

}


To know about the other details of MvRx, you can refer to its GitHub repository and also read Airbnb’s official announcement.

RxAndroid 2.1.0 is out with a newly added Async API!

Dagger 2.17, a dependency injection framework for Java and Android, is now out!

Did you know your idle Android device sends data to Google 10 times more often than an iOS device does to Apple?