Comments (7)
自己检查下Observer对象是否导入错了
from rxlife.
去掉
.to(RxLife.to(this))
就运行正常
from rxlife.
那就是你Observable对象的泛型不对,takeUntil
操作符应该返回了Observable对象,应该需要返回Observable对象
from rxlife.
不对,请贴上你完整源码,还不清楚,你用的Observable还是Flowable,或者其他。
from rxlife.
不对,请贴上你完整源码,还不清楚,你用的Observable还是Flowable,或者其他。
public class Erweimalogin {
private int code;
private String msg;
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
}
public interface Lejia {
@GET("weixin/login/xcx")
Observable<Erweimalogin> erweima_login(@Query("token") String token);
}
private boolean isgetuser = false;
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://" + G.gStrYuMing + "/") // 设置 网络请求 Url
.addConverterFactory(GsonConverterFactory.create()) //设置使用Gson解析(记得加入依赖)
.addCallAdapterFactory(RxJava3CallAdapterFactory.create()) // 支持RxJava
.build();
// 创建 网络请求接口 的实例
Lejia request = retrofit.create(Lejia.class);
Observable observable = request.erweima_login("test123");
observable.delay(1, TimeUnit.SECONDS)
.repeatUntil(new BooleanSupplier() {
@Override
public boolean getAsBoolean() throws Exception {
return isgetuser;
}
})
.retryWhen(new RetryWithDelay(20,1000))
.takeUntil(new Predicate<Erweimalogin>() {
@Override
public boolean test(Erweimalogin integer) throws Exception {
return (integer.getCode() == 1);
// 返回true时,就停止发送事件
}
})
.subscribeOn(Schedulers.io()) // 切换到IO线程进行网络请求
.observeOn(AndroidSchedulers.mainThread()) // 切换回到主线程 处理请求结果
// .to(RxLife.toMain(this))
.subscribe(new Observer<Erweimalogin>() {
@Override
public void onSubscribe(Disposable d) {
Log.d(TAG, "dingyue");
disposable=d;
}
@Override
public void onNext(Erweimalogin result) {
// e.接收服务器返回的数据
Log.i(TAG, String.valueOf(result.getMsg()));
}
@Override
public void onError(Throwable e) {
// 获取轮询结束信息
Log.d(TAG, e.toString());
}
@Override
public void onComplete() {
Log.d(TAG, "完成");
}
});
from rxlife.
public class Presenter extends BaseScope {
private boolean isgetuser = false;
public Presenter(LifecycleOwner owner) {
super(owner); //添加生命周期监听
}
public void test1() {
//步骤1:创建Retrofit对象
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://" + G.gStrYuMing + "/") // 设置 网络请求 Url
.addConverterFactory(GsonConverterFactory.create()) //设置使用Gson解析(记得加入依赖)
.addCallAdapterFactory(RxJava3CallAdapterFactory.create()) // 支持RxJava
.build();
// 步骤2:创建 网络请求接口 的实例
Lejia request = retrofit.create(Lejia.class);
Observable observable = request.erweima_login("test123");
// 步骤3:发送网络请求进行轮询
observable.delay(1, TimeUnit.SECONDS)
.repeatUntil(new BooleanSupplier() {
@Override
public boolean getAsBoolean() throws Exception {
return isgetuser;
}
})
.retryWhen(new RetryWithDelay(20,1000))
.takeUntil(new Predicate<Erweimalogin>() {
@Override
public boolean test(Erweimalogin integer) throws Exception {
return (integer.getCode() == 1);
// 返回true时,就停止发送事件
}
})
.subscribeOn(Schedulers.io()) // 切换到IO线程进行网络请求
.observeOn(AndroidSchedulers.mainThread()) // 切换回到主线程 处理请求结果
// .to(RxLife.toMain(this))
.subscribe(new Observer<Erweimalogin>() {
@Override
public void onSubscribe(Disposable d) {
Log.d(TAG, "dingyue");
disposable=d;
}
@Override
public void onNext(Erweimalogin result) {
// e.接收服务器返回的数据
Log.i(TAG, String.valueOf(result.getMsg()));
}
@Override
public void onError(Throwable e) {
// 获取轮询结束信息
Log.d(TAG, e.toString());
}
@Override
public void onComplete() {
Log.d(TAG, "完成");
}
});
}
}
from rxlife.
Observable<Erweimalogin> observable = request.erweima_login("test123");
返回值要明确泛型
from rxlife.
Related Issues (20)
- 返回结果是 SingleLife 而不是 Single,是不是意味着就要放弃 RxKotlin 这个库 HOT 1
- RxJava3怎么使用呢 HOT 1
- 偶发性报ClassCastException这个错误 HOT 4
- rxLifeScope.launch { } 线程选择 HOT 3
- 关于presenter需要继承BaseScope的疑问 HOT 2
- demo中的observableByVM点击事件崩溃了 HOT 1
- 引入最新的rxlife-rxjava2报错 HOT 1
- com.rxjava.rxlife.OutsideScopeException: View is not attached HOT 1
- onFinally中没有判断isActive HOT 1
- .life(this) 需要引入什么库吗。为什么敲不出来呀 HOT 3
- LifeObserver类的异常捕获问题 HOT 1
- ViewModelProvider(this).get(MyViewModel::class.java) HOT 2
- 使用.to操作符后 ,crash HOT 2
- 求教 HOT 1
- LifecycleScope 移除 Observer 的疑问 HOT 8
- Rxlife的BaseScope不支持Service?目前项目中,会在服务里也会用到Rxjava HOT 2
- 在View中是否无法使用 HOT 2
- 兼容有问题 HOT 1
- rxjava3中的Observable位于其core包下 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rxlife.