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

How replace returned observable with a new one RxJava2

user1445
1#
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();

   @Override
    public Flowable<byte[]> startStreamRead() {
        bindToService();
        return mFlowableStream;
    }

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

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

    @Override
    public void onServiceConnected(ComponentName name, IBinder binder) {

       mServiceInterection = ((StreamServiceInterection.LocalBinder) binder).getServiceInteractor();
        mStreamDisposable = mServiceInterection.getStream()
                .subscribe(new Consumer<byte[]>() {
                    @Override
                    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

Thanks

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