RxJava and Rxandroid III (Life cycle control and memory optimization)

Source: Internet
Author: User

RxJava and Rxandroid III (Life cycle control and memory optimization) rxjavarxandroid

Rxjava, rxandroid do not understand the students can first see
RxJava and Rxandroid
RxJava and Rxandroidrxjava and Rxandroid II (use of Operators)

Rxjava makes it easy to use chained programming, and the code looks both concise and elegant. However, the use of Rxjava is also a side effect, the use of more and more subscriptions, memory costs will become very large, a bit of inattention will be a memory overflow situation, this article is to introduce Rxjava use process should be noted.

1, unsubscribe subscription.unsubscribe ();
Package Lib.com.myapplication;import android.os.bundle;import android.support.v7.app.appcompatactivity;import Rx. Observable;import Rx. Subscription;import Rx.functions.action1;public class Mainactivity extends Appcompatactivity {Subscription Subscripti    On;        @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);        Setcontentview (R.layout.activity_main); subscription = Observable.just ("123"). Subscribe (New action1<string> () {@Override public voi            D Call (String s) {System.out.println ("tt--" + s);    }        }) ;        } @Override protected void OnDestroy () {Super.ondestroy ();        Unsubscribe if (subscription! = null) {subscription.unsubscribe (); }    }}

RxJava and Rxandroid III (Life cycle control and memory optimization)

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.