Skip to content

Commit a08e6ef

Browse files
committed
Update sample to compile with latest RxJava 2.0 APIs.
1 parent ff6f745 commit a08e6ef

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

sample-app/src/main/java/io/reactivex/android/samples/MainActivity.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,16 @@
2121
import io.reactivex.Observable;
2222
import io.reactivex.ObservableSource;
2323
import io.reactivex.android.schedulers.AndroidSchedulers;
24-
import io.reactivex.observers.AsyncObserver;
24+
import io.reactivex.disposables.CompositeDisposable;
25+
import io.reactivex.observers.DisposableObserver;
2526
import io.reactivex.schedulers.Schedulers;
2627
import java.util.concurrent.Callable;
2728

2829
public class MainActivity extends Activity {
2930
private static final String TAG = "RxAndroidSamples";
3031

32+
private final CompositeDisposable disposables = new CompositeDisposable();
33+
3134
@Override protected void onCreate(Bundle savedInstanceState) {
3235
super.onCreate(savedInstanceState);
3336
setContentView(R.layout.main_activity);
@@ -38,13 +41,18 @@ public class MainActivity extends Activity {
3841
});
3942
}
4043

44+
@Override protected void onDestroy() {
45+
super.onDestroy();
46+
disposables.clear();
47+
}
48+
4149
void onRunSchedulerExampleButtonClicked() {
42-
sampleObservable()
50+
disposables.add(sampleObservable()
4351
// Run on a background thread
4452
.subscribeOn(Schedulers.io())
4553
// Be notified on the main thread
4654
.observeOn(AndroidSchedulers.mainThread())
47-
.subscribe(new AsyncObserver<String>() {
55+
.subscribeWith(new DisposableObserver<String>() {
4856
@Override public void onComplete() {
4957
Log.d(TAG, "onComplete()");
5058
}
@@ -56,7 +64,7 @@ void onRunSchedulerExampleButtonClicked() {
5664
@Override public void onNext(String string) {
5765
Log.d(TAG, "onNext(" + string + ")");
5866
}
59-
});
67+
}));
6068
}
6169

6270
static Observable<String> sampleObservable() {

0 commit comments

Comments
 (0)