Android RxJava创建操作符Interval
作者:Adan0520 时间:2023-08-14 01:26:24
Interval操作符:用于创建Observable,跟TimerTask类似,用于周期性发送信息,是一个可以指定线程的TimerTask
首先添加类库
// RxAndroid
compile 'io.reactivex:rxandroid:1.2.1'
// RxJava
compile 'io.reactivex:rxjava:1.2.4'
(1) 间隔时间3秒发送一次
private Subscription subscribe;
private void start() {
if (subscribe == null || subscribe.isUnsubscribed()) {
subscribe = Observable.interval(3000, 3000, TimeUnit.MILLISECONDS)//延时3000 ,每间隔3000,时间单位
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Action1<Long>() {
@Override
public void call(Long aLong) {
Log.e("1234", "执行一次");
}
});
}
}
(2)取消订阅
private void stop() {
if (subscribe != null && !subscribe.isUnsubscribed()) {
subscribe.unsubscribe();
Log.e("1234", "停止");
}
}
来源:http://blog.csdn.net/qq_20785431/article/details/73105840
标签:Android,RxJava,Interval
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
详解ASP.NET中Identity的身份验证代码
2022-05-20 04:43:48
![](https://img.aspxhome.com/file/2023/5/108815_0s.png)
Android动画之逐帧动画(Frame Animation)实例详解
2023-02-27 06:12:56
Android监听Home键和Back键的区别介绍
2022-09-11 11:21:03
OpenGL绘制三次Bezier曲线
2022-04-23 18:18:14
![](https://img.aspxhome.com/file/2023/3/112283_0s.jpg)
Spring Boot 单元测试JUnit的实践
2023-08-29 02:02:15
![](https://img.aspxhome.com/file/2023/7/91127_0s.png)
mybatis plus中如何编写sql语句
2021-09-21 15:27:55
![](https://img.aspxhome.com/file/2023/1/83121_0s.png)
Android实现分享功能
2023-12-08 10:10:48
Android仿QQ微信侧滑删除效果
2023-07-08 11:22:15
![](https://img.aspxhome.com/file/2023/0/100590_0s.jpg)
Android 通过代码安装 APK的方法详解
2022-11-12 14:37:26
简单实现Android读取网络图片到本地
2021-12-20 04:31:05
Java基础篇之反射机制示例详解
2021-12-08 04:05:25
![](https://img.aspxhome.com/file/2023/9/113379_0s.png)
C语言连续生成多个随机数实现可限制范围
2023-08-24 08:35:06
![](https://img.aspxhome.com/file/2023/3/127553_0s.png)
Java实现简单班级管理系统
2023-01-07 16:20:29
![](https://img.aspxhome.com/file/2023/0/66630_0s.jpg)
深入同步访问共享的可变数据分析
2023-05-08 00:16:49
C#使用文件流读取文件的方法
2022-06-27 20:17:12
java实现多线程的两种方式继承Thread类和实现Runnable接口的方法
2022-07-24 04:27:18
代码详解Java猴子选王问题(约瑟夫环)
2023-09-16 07:33:43
Java正则多字符串匹配替换
2021-12-16 02:24:48
Android 中 ActivityLifecycleCallbacks的实例详解
2022-08-12 06:03:34
java实现数字转换人民币中文大写工具
2023-08-16 08:48:41
![](https://img.aspxhome.com/file/2023/8/131988_0s.jpg)