Android 在使用改型时如何在RxJava中使用startWith方法

Android 在使用改型时如何在RxJava中使用startWith方法,android,retrofit,rx-java,Android,Retrofit,Rx Java,使用RxJava对进行改装时,我试图传递加载、成功和错误状态。我的输出由改造包中的响应包装,并希望使用RxJava中的startWith方法,以便从资源类传递加载状态。当我添加startWith时,代码不工作并且有语法错误 改装接口: @POST @FormUrlEncoded Flowable<Response<ResponseMobileGetAccess>> getAccess(@Url String url, @FieldMap HashMap<String

使用
RxJava
进行改装时,我试图传递加载、成功和错误状态。我的输出由
改造
包中的
响应
包装,并希望使用
RxJava
中的
startWith
方法,以便从
资源
类传递
加载
状态。当我添加
startWith
时,代码不工作并且有语法错误

改装接口:

@POST
@FormUrlEncoded
Flowable<Response<ResponseMobileGetAccess>> getAccess(@Url String url, @FieldMap HashMap<String, Object> requestModel);
@POST
@FormUrlEncoded
可流动的getAccess(@Url字符串Url,@FieldMap HashMap requestModel);
我使用RxJava执行此方法的位置:

 public Flowable<Resource<ResponseMobileGetAccess>> registerMobile(
        @NonNull String username) {

    HashMap<String, Object> body = new HashMap<>();
    body.put("param1", ACTION_MOBILE_GET_ACCESS);

    return Flowable
            .defer(() -> localAccountMobileApiService.getAccess(ACTION_MOBILE_GET_ACCESS, body)
            .map(response -> {
                if (responseMobileGetAccessResponse.isSuccessful()) {
                    return Resource.success(responseMobileGetAccessResponse.body());
                } else {
                    return Resource.error();
                }
            })).startWith(Resource.loading());
}
公共可流动寄存器移动(
@非空字符串(用户名){
HashMap body=newhashmap();
body.put(“param1”,ACTION\u MOBILE\u GET\u ACCESS);
回流
.defer(()->localAccountMobileApiService.getAccess(操作\u移动\u获取\u访问,正文)
.map(响应->{
if(responseMobileGetAccessResponse.isSuccessful()){
返回Resource.success(responseMobileGetAccessResponse.body());
}否则{
返回Resource.error();
}
})).startWith(Resource.loading());
}

提前感谢

我刚刚将这些代码更改为:

 public Flowable<Resource<ResponseMobileGetAccess>> registerMobile(
        @NonNull String username) {

    HashMap<String, Object> body = new HashMap<>();
    body.put("param1", ACTION_MOBILE_GET_ACCESS);

    Flowable<Resource<ResponseMobileGetAccess>> defer = Flowable
            .defer(() -> localAccountMobileApiService.getAccess(ACCOUNT_MOBILE_URL, body)
                    .map(response -> {

                        if (response.isSuccessful()) {
                            ResponseMobileGetAccess data = response.body();

                            if (data != null) {

                                if (data.getStatusCode() > 0) {
                                    return Resource.success(data);
                                } else {
                                    return Resource.serverFailed(data.getStatusText());
                                }

                            } else {
                                return Resource.httpFailed();
                            }

                        } else {
                            return Resource.httpFailed();
                        }

                    }));

    return defer.startWith(Resource.loading());
}
公共可流动寄存器移动(
@非空字符串(用户名){
HashMap body=newhashmap();
body.put(“param1”,ACTION\u MOBILE\u GET\u ACCESS);
可流动延迟=可流动
.defer(()->localAccountMobileApiService.getAccess(ACCOUNT\u MOBILE\u URL,body)
.map(响应->{
if(response.issusccessful()){
ResponseMobileGetAccess数据=response.body();
如果(数据!=null){
if(data.getStatusCode()>0){
返回资源成功(数据);
}否则{
返回Resource.serverFailed(data.getStatusText());
}
}否则{
返回资源。httpFailed();
}
}否则{
返回资源。httpFailed();
}
}));
返回defer.startWith(Resource.loading());
}
虽然我不确定这是一个标准的方法,但它是有效的