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)