rx-java2

What's the correct way to unsubscribe from Single [duplicate]

*爱你&永不变心* 提交于 2020-01-06 07:14:02
问题 This question already has answers here : The result of subscribe is not used (6 answers) Closed 9 months ago . I want to do something after short delay: public void notifyMe() { Single .timer(500, TimeUnit.MILLISECONDS) .subscribeOn(Schedulers.io()) .subscribe(ignore -> service.notifyMe())); } Now I have a warning: "The result of subscribe is not used" . How can I fix it? 回答1: A Single will only call once. Upon calling either method, the Single terminates and the subscription to it ends. Link

arraylist add to new recyclerview

故事扮演 提交于 2020-01-06 05:25:26
问题 Hi I am trying to add a new item to my chat, I use RXJava2, to make call to my REST API to get the chat data, with this nested json response. But I get an NullPointer when I try to add a new item to the Arraylist (Send new message): 09-08 13:35:14.529 2869-2869/com.jonathan.myapp E/AndroidRuntime: FATAL EXCEPTION: main Process: com.jonathan.myapp, PID: 2869 java.lang.NullPointerException: Attempt to invoke virtual method 'void com.jonathan.myapp.models.ChatMessageUser.setUserId(java.lang

android rxjava2/retrofit2 chaining calls with pagination token

瘦欲@ 提交于 2020-01-05 04:54:30
问题 I'm using a REST API to query for a list of Person objects. Max limit is 100 people in response. I need to fetch all people, and the total amount is unknown. There is a field in the first response called "next", containing url for the next page. I need to chain these calls using RxJava/RxAndroid and Retrofit until the last response has an empty "next" field. Since the "next" field contains a pagination url, all subsequent calls will have different url from the first one. What is the most

State machine using RxJava?

独自空忆成欢 提交于 2020-01-05 04:39:08
问题 I'm trying to go all in on RxJava and solve this problem I have with it, but it seems very unsuited for it, as RxJava seems to not want to deal with having any sort of state, rather only passing along events and mutating them to handle them. The basic state machine behavior I'm trying to emulate with RxJava is this: On app start event, wait for the next app pause. On app pause event, start a 15 minute timer and wait for the next app resume. If the app resumes within the timer, cancel it and

RxJava - single thread asynchronous processing

£可爱£侵袭症+ 提交于 2020-01-05 04:06:47
问题 I have a question. Is possible run two tasks asynchronously in single threaded environment in RxJava? I know that Java should contain library for this functionality, but i think that RxJava does not contain it. 回答1: Of course it contains single threaded asynchronous processing at it contains any thread count processing. Example Flowable.fromCallable(() ->{ // do something }) .subscribeOn(Schedulers.single()); Alternatives to Schedulers.single() is Schedulers.from(Executors.newFixedThreadPool

How to make Observable that emit character after 1 second of time interval

旧巷老猫 提交于 2020-01-04 18:31:20
问题 I have just started with RxJava/android and for practice and getting started I want to make observable that emits character in string every 1 second, how can I do this? Here is what I have tried so far, its just emit string at once: Observable<String> myObservable = Observable.interval(5000L, TimeUnit.MILLISECONDS) .observeOn(AndroidSchedulers.mainThread()) .just("Hello"); I want hello like this first emit H after 1 second emit E and so on 回答1: Split String "hello" into letters "h", "e", ...

RxJava - “Only one emission is allowed to travel up the Observable chain at a time…”

我们两清 提交于 2020-01-04 09:48:17
问题 I'm reading a blog post here: http://tomstechnicalblog.blogspot.com/2016/02/rxjava-understanding-observeon-and.html where it is said that No matter what Scheduler you are subscribed on, only one emission is allowed to travel up the Observable chain of operators at a time. Below, you can observe that the emission must be pushed all the way from the source to the Subscriber before the next emission can start. Right above that quoted text is an example written as: public static void main(String[

Best way to repeat an observable every minute rxjava

北城余情 提交于 2020-01-03 08:50:11
问题 I have the following method: public class ParentalControlInteractor { public Single<Boolean> isPinSet() { return bamSdk.getPinManager().isPINSet(); } } I want to call this function to run once, then repeat every minute until infinity but this seems clumsy: parentalControlInteractor.isPinSet() .subscribeOn(Schedulers.io()) .repeat(10000) .timeout(1600,TimeUnit.MILLISECONDS) .doOnError(throwable -> { Timber.e(throwable,"Error getting if Pin is set"); throwable.printStackTrace(); }) .subscribe

How can I explicitly signal completion of a Flowable in RxJava?

倖福魔咒の 提交于 2020-01-02 05:27:20
问题 I'm trying to create a Flowable which is wrapping an Iterable . I push elements to my Iterable periodically but it seems that the completion event is implicit. I don't know how to signal that processing is complete. For example in my code: // note that this code is written in Kotlin val iterable = LinkedBlockingQueue<Int>() iterable.addAll(listOf(1, 2, 3)) val flowable = Flowable.fromIterable(iterable) .subscribeOn(Schedulers.computation()) .observeOn(Schedulers.computation()) flowable

How to handle dispose in RxJava without InterruptedException

。_饼干妹妹 提交于 2020-01-01 17:07:09
问题 In the below code snipped when dispose() is called, then the emitter thread is interrupted ( InterruptedException is thrown out of sleep method). Observable<Integer> obs = Observable.create(emitter -> { for (int i = 0; i < 10; i++) { if (emitter.isDisposed()) { System.out.println("> exiting."); emitter.onComplete(); return; } emitter.onNext(i); System.out.println("> calculation = " + i); try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } emitter.onComplete()