0
votes

New in rxJava I'm struggling in order to get an Observable by nesting retrofit Observables. On the code block .map(userResponse -> { data.put final Intent resd = new Intent(); resd.putExtras(data); return (Intent)resd; });

I get a cyclic inference error. When I try to compile I get a weird message I don't quite understand as :

Error:(52, 21) error: incompatible types: cannot infer type-variable(s) R (argument mismatch; bad return type in lambda expression Intent cannot be converted to Observable) where R,T are type-variables: R extends Object declared in method flatMap(Func1>) T extends Object declared in class Observable

here is the code:

public Observable<Intent> createUser(final String email) {
    Bundle data = new Bundle();
    return mWebservice.clientAuth("myFakeClientId") //returns an Observable<AccessToken>
            .map(clientTokenObject -> {
                String clientToken = clientTokenObject.accessToken;
                Observable<Response<User>> userResponseObservable = mWebservice.createAccount(email);
                Observable<Intent> resultObs =  userResponseObservable
                                .map(userResponse -> {
                                    final Intent resd = new Intent();
                                    resd.putExtras(data);
                                    return (Intent)resd;
                                });
                        return resultObs;
                    });
}

;(

1

1 Answers

3
votes

Your mapping is wrong. You need something like

public Observable<Intent> createUser(final String email) {

    return mWebservice.clientAuth("myFakeClientId") //returns an Observable<AccessToken>
                      .map(clientTokenObject  -> clientTokenObject.accessToken)
                      .flatMap(accessToken -> { mWebservice.createAccount(email).
                                                       .map(userResponse -> {
                                                                final Intent resd = new Intent();
                                                                Bundle data = new Bundle();
                                                                resd.putExtras(data);
                                                                return (Intent)resd;
                                                            })});

}