Android开发RxJava3延迟操作
直接上代码:
/*** @param timeMillis 毫秒单位* @desc : 延迟多少毫秒操作,* 注:它和Activity生命周期绑定,界面关闭了不会再执行delayTodoListener.delayTodo()* @author : congge on 2021-03-25 15:31**/public static void delayTimeTodo(RxAppCompatActivity appCompatActivity, int timeMillis, final DelayTodoListener delayTodoListener){if (appCompatActivity == null) return;Observable.timer(timeMillis, TimeUnit.MILLISECONDS).compose(appCompatActivity.<Long>bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Consumer<Long>() {@Overridepublic void accept(Long aLong) throws Exception {if (delayTodoListener != null) {delayTodoListener.delayTodo();}}}, new Consumer<Throwable>() {@Overridepublic void accept(Throwable throwable) throws Exception {}});}
调用示例:
RxJavaUtil.delayTimeTodo((RxAppCompatActivity) mContext, 500, new RxJavaUtil.DelayTodoListener() {@Overridepublic void delayTodo() {// 做你的延迟后的操作//remove(position);}});