RxJava core

 

ObserverAnd Subscriberit is exactly the same. They differ mainly two things for the user:

  1. onStart(): This is the Subscriberadded methods. It just started subscribe, to be called before the event has not been sent, can be used to do some preparatory work, such as clear or reset data. This is an optional method, by default, its implementation is empty. Note that, if required (for example, pops up a dialog box displays progress, which must be executed in the main thread) on the thread is ready to work, onStart()it does not apply, because it is always called in the thread subscribe occurred, and You can not specify thread. To do the preparatory work in the specified thread, you can use doOnSubscribe()the method, specific can be seen in the back of the text.
  2. unsubscribe(): This is Subscriberanother interface implemented Subscriptionmethod for unsubscribe. After this method is called, Subscriberit will no longer receive event. General before this method is called, can be used isUnsubscribed()to determine what status. unsubscribe()This method is very important, because subscribe()after, Observablewill hold Subscribera reference to this quote if you can not be released, there is a risk of memory leaks. So it is best to keep one principle: to be in the right place (for example, as soon as possible when no longer in use onPause() onStop()and other methods) to call unsubscribe()to dereference relations, in order to avoid memory leaks.

Author: Scus
link: https: //juejin.im/post/5a224cc76fb9a04527256683
Source: Nuggets
copyright reserved by the authors. Commercial reprint please contact the author authorized, non-commercial reprint please indicate the source.
 
 

Guess you like

Origin www.cnblogs.com/cx2016/p/12241996.html