Skip to content

Commit 8698d31

Browse files
author
Kaushik Gopal
committed
docs: update README with examples
1 parent 958214c commit 8698d31

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

README.md

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,35 @@
1-
Android-RxJava
1+
Android-RxJava : Learning RxJava for Android by example
22
==============
33

4-
Learning RxJava for Android by example
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+
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 deatils on the approach:
7+
8+
## Examples:
9+
10+
### 1. Concurrency using schedulers
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 onc ompletion, back into the UI/main thread. 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!
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.
15+
16+
To really see this 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+
18+
19+
### 2. Accumulate calls using buffer (wip)
20+
21+
This is a demo of how events can be accumulated using the "buffer" operation.
22+
23+
A button is provided and we accumulate the number of clicks on that button, over a span of time and then spit out the final results.
24+
25+
If you hit the button once. you'll get message saying the button was hit once. If you hit it 5 times continuosly within a span of 2 seconds, then you get a single log, saying you hit that button 5 times (vs 5 individual logs saying Button hit once).
26+
27+
### 3. Instant/Auto searching (using a subject and debounce)
28+
29+
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".
30+
31+
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. \n\nThis is the debounce/throttleWithTimeout method in RxJava.
32+
33+
### 4. Replacing your event Bus (wip)
34+
35+
http://stackoverflow.com/questions/19266834/rxjava-and-random-sporadic-events-on-android

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
<string name="hello_world">Hello world!</string>
66
<string name="action_settings">Settings</string>
77

8-
<string name="msg_demo_buffer">This is a demo of how events can be accumulated using the "buffer" operation. Tap the button below repetitively and you will notice in the logs that button taps are collected over a span of 2s and printed below.</string>
98
<string name="msg_demo_concurrency_schedulers">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! \n\n To really see this 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</string>
9+
<string name="msg_demo_buffer">This is a demo of how events can be accumulated using the "buffer" operation. Tap the button below repetitively and you will notice in the logs that button taps are collected over a span of 2s and printed below.</string>
1010
<string name="msg_demo_subject">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. \n\nThis is the debounce/throttleWithTimeout method in RxJava.</string>
1111

1212
<string name="btn_demo_schedulers">bg work (schedulers &amp; concurrency)</string>

0 commit comments

Comments
 (0)