RxJava Android (rxandroid) Development family Bucket

Source: Internet
Author: User

RxJava is becoming more popular in Android application development, but because of its higher threshold, the initial use inevitably encounters many problems, such as those described in RxJava Common error usage and situations where RxJava should not be used. To avoid these common problems, many folk experts have developed many Rx extension libraries that can be used in Android applications, combined with these libraries, to make it easier to use RxJava and to avoid some common error usages. This article describes some of the extension libraries that are required to use RxJava.

Rxandroid

Rxandroid This is no doubt, Android development using the RxJava necessary elements, although the inside just provides a simple two features. Androidschedulers.mainthread () and Androidschedulers.handlerthread (handler), but this is one of the core features of Android development.

Rxbinding

Rxbinding is the conversion of events from various UI controls in Android to data streams in RxJava. This allows the UI control's events to be used as data streams in RxJava. For example, the View OnClick event, use Rxview.clicks (view) to get to a Observable object, each time the user clicks on the view, the Observable object launches an event (OnNext is called), Ob Servable Observer subscribers can know by OnNext callback that the user clicked the View.

Rxlifecycle

Rxlifecycle with the Activity/fragment lifecycle to manage subscriptions. Since the RxJava Observable subscription (called the Subscribe function), it typically performs some operations on the background thread (such as accessing network request data), and when the background operation returns, calls the OnNext function such as Observer, and then updates the UI state. However, the background thread request is time, if the user click the Refresh button to request a new microblogging information, when the refresh has not been completed, the user exited the current interface to return to the previous interface, this time the refresh of the Observable if not unsubscribe, will cause the previous Activity can not be the JVM Recycling causes a memory leak. This is where life cycle management in Android needs attention, and rxlifecycle is used to do it. such as the following example:

myObservable    .compose(RxLifecycle.bindUntilEvent(lifecycle, ActivityEvent.DESTROY))    .subscribe();

When the Activity is destroyed, Rxlifecycle will automatically unsubscribe from this Observer. So you don't have to manage it manually.

Retrofit

Almost all Android applications now need to request data from the network, while Retrofit is a library for simplifying network requests and supporting RxJava. Like what:

    @GET("/users/{user}")    Observable<User> user(@Path("user") String user);

The above code defines a GET request with a path of/users/{user} and a parameter with a user name. The returned result is a Observable. In this way, with the previous rxbinding, it is easy to implement a user click on a refresh button to request server data operation.
Rxview.clicks (view). FlatMap (V-githubservice.user (user)). Subscribe ();

Sqlbrite

If your app uses Sqlite to save data, then Sqlbrite is a good library to work with RxJava.

In addition to these main class libraries, there are libraries that encapsulate other Android services:

    • The Rx Preferences accesses the sharedpreferences by RxJava Way.
    • The rxpermissions is used to support Android M dynamic permission requests for libraries.

There are also some libraries that work with Google Play service:

    • Rxfit encapsulates the invocation of the Fitness API.
    • The rxnotification encapsulates the Firebase notification API.
    • Android-reactivelocation encapsulates the Google Play Service API and location-related APIs.

If you are developing an Android Wear application, you will use the wearable API for direct data communication between your watch and your phone, and you can use the Rxwear library.

RxJava Android (rxandroid) Development family Bucket

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.