Home How replace returned observable with a new one RxJava2
Reply: 0

How replace returned observable with a new one RxJava2

user1445 Published in June 23, 2018, 9:22 pm

I have one case when I need to return an observable immediately, but then replace this observable with another one.

Here is an example

    private Flowable<byte[]> mFlowableStream = Flowable.empty();

    public Flowable<byte[]> startStreamRead() {
        return mFlowableStream;

And then after binding to service I provide it a callback connection like that

public void bindToService() {
    mAppContext.bindService(new Intent(mAppContext,StreamService.class), mServiceConnection, 0);

    public void onServiceConnected(ComponentName name, IBinder binder) {

       mServiceInterection = ((StreamServiceInterection.LocalBinder) binder).getServiceInteractor();
        mStreamDisposable = mServiceInterection.getStream()
                .subscribe(new Consumer<byte[]>() {
                    public void accept(byte[] data) throws Exception {


What I want to do is to somehow replace returned previously mFlowableStream with a new observable that I got from service.

What are possible strategies to implement this ? Maybe I should return some other value, like Future.

Please suggest how to solve this problem


You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.379412 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO