You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+25-30Lines changed: 25 additions & 30 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,39 +3,27 @@ Learning RxJava for Android by example
3
3
4
4
I've read and watched a lot on Rx. Most examples either use the J8 lambda notations/Scala/Groovy or some other awesome language that us Android developers are constantly envious of.
5
5
6
-
Unfortunately i could never find real-world simple examples in Android, that could show me how to use RxJava in Android. This repo is a solution to that problem. Below are a list of examples with a little more details on the approach:
6
+
Unfortunately i could never find real-world simple examples in Android, that could show me how to use RxJava in Android. This repo is a solution to that problem.
7
7
8
8
## Examples:
9
9
10
-
### 1. Concurrency using schedulers
10
+
### Concurrency using schedulers
11
11
12
-
A common requirement is to offload lengthy heavy I/O intensive operations to a background thread (non-UI thread), and feed the results back to the UI/main thread, on completion. This is a demo of how long running operations can be offloaded to a background thread. After the operation is done, we resume back on the main thread. All using RxJava! Think of this is as a replacement for AsyncTasks.
12
+
A common requirement is to offload lengthy heavy I/O intensive operations to a background thread (non-UI thread), and feed the results back to the UI/main thread, on completion. This is a demo of how long running operations can be offloaded to a background thread. After the operation is done, we resume back on the main thread. All using RxJava! Think of this as a replacement to AsyncTasks.
13
13
14
-
The long operation is simulated by a blocking Thread.sleep call. But since it's in a background thread, our UI is never interrupted.
14
+
The long operation is simulated by a blocking Thread.sleep call (since this is done in a background thread, our UI is never interrupted).
15
15
16
16
To really see this example shine. Hit the button multiple times and see how the button click (which is a ui operation) is never blocked because the long operation only runs in the background.
17
17
18
-
### 1. Retrofit and RxJava (zip, flatmap) (wip)
18
+
### Instant/Auto searching (subject + debounce)
19
19
20
-
Working examples of github from JakeWharton's Retrofit preso at Netflix
### 1. Make two parallel network calls, then combine the result into a single data point (zip) (wip)
20
+
This is a demo of how events can be swallowed in a way that only the last one is respected. A typical example of this is instant search result boxes. As you type the word "Bruce Lee", you don't want to execute searches for B, Br, Bru, Bruce, Bruce , Bruce L ... etc. But rather intelligently wait for a couple of moments, make sure the user has finished typing the whole word, and then shoot out a single call for "Bruce Lee".
As you type in the input box, it will not shoot out log messages at every single input character change, but rather only pick the lastly emitted event (i.e. input) and log that.
36
23
24
+
This is the debounce/throttleWithTimeout method in RxJava.
37
25
38
-
### 1. Accumulate calls (buffer)
26
+
### Accumulate calls (buffer)
39
27
40
28
This is a demo of how events can be accumulated using the "buffer" operation.
41
29
@@ -48,15 +36,24 @@ Two implementations:
48
36
2a. Using a traditional observable - but encompassing the OnClick within the observable
49
37
2b. Using PublishSubject and sending single clicks to the Observable, which in-turn then sends it to the Observer
This is a demo of how events can be swallowed in a way that only the last one is respected. A typical example of this is instant search result boxes. As you type the word "Bruce Lee", you don't want to execute searches for B, Br, Bru, Bruce, Bruce , Bruce L ... etc. But rather intelligently wait for a couple of moments, make sure the user has finished typing the whole word, and then shoot out a single call for "Bruce Lee".
41
+
### Retrofit and RxJava (zip, flatmap) (wip)
54
42
55
-
As you type in the input box, it will not shoot out log messages at every single input character change, but rather only pick the lastly emitted event (i.e. input) and log that.
43
+
Working examples of github from JakeWharton's Retrofit preso at Netflix
If actions A and B depend on action X running; and action C depends on action Y running. What if you want to combine the result of all those calls and have a single output?
62
59
@@ -66,15 +63,13 @@ If actions A and B depend on action X running; and action C depends on action Y
0 commit comments