π§
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
subscription.unsubscribe(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainActivity extends BaseActivity { | |
private CompositeSubscription mSubscription = new CompositeSubscription(); | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
//... | |
//... | |
//... | |
mSubscription.add(subscription1); //Add subscription 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Action1<Integer> onNextAction = new Action1<Integer>() { | |
@Override | |
public void call(Integer s) { //This is eqivelent to onNext() | |
System.out.println(s); | |
} | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
android { | |
buildToolsVersion β21.1.2β//Use the latest version at the time. | |
defaultConfig { | |
// Enable the experimental Jack build tools. | |
jackOptions { | |
enabled true | |
} | |
} | |
... | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
android { | |
defaultConfig { | |
jackOptions { | |
enabled true | |
} | |
} | |
//Add support for java 8 features. | |
compileOptions { | |
sourceCompatibility JavaVersion.VERSION_1_8 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Observable.from(new Integer[]{1, 2, 3, 4, 5}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Observable<Integer> observer1 = Observable.from(new Integer[]{1, 2, 3, 4, 5}); //Emit 1 to 5 | |
Observable<Integer> observer2 = Observable.from(new Integer[]{6, 7, 8, 9, 10}); //Emit 6 to 10 | |
Observable.concat(observer1, observer2) //Concat the output of both the operators. | |
.subscribeOn(Schedulers.newThread()) | |
.observeOn(Schedulers.io()) | |
.subscribe(new Action1<Integer>() { | |
@Override | |
public void call(Integer integer) { | |
Log.d("Observer", "Output:" + integer); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Observable<Integer> observer1 = Observable.from(new Integer[]{1, 2, 3, 4, 5}); | |
Observable<Integer> observer2 = Observable.from(new Integer[]{6, 7, 8, 9, 10}); | |
Observable.merge(observer1, observer2) | |
.subscribeOn(Schedulers.newThread()) | |
.observeOn(Schedulers.io()) | |
.subscribe(new Action1<Integer>() { | |
@Override | |
public void call(Integer integer) { | |
Log.d("Observer", "Output:" + integer); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Create observable | |
Observable<String> observable = Observable | |
.from(new Integer[]{1,2,3,4,5}) | |
.map(new Func1<Integer, String>() { | |
@Override | |
public String call(Integer integer) { | |
return integer + "ABC"; //Convert integer to string and emmit | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Class that combines both data streams | |
class ZipObject { | |
int number; | |
String alphabet; | |
} | |
Observable<Integer> observable1 = Observable.from(new Integer[]{1, 2, 3, 4, 5}); //Emits integers | |
Observable<String> observable2 = Observable.from(new String[]{"A", "B", "C", "D", "F"}); //Emits alphabets | |
Observable<ZipObject> observable = Observable.zip(observable1, observable2, | |
//Function that define how to zip outputs of both the stream into single object. |