If you’ve used an AsyncTask before this code should look familiar. Inside the
doInBackground method I make a network request to some given URL, and return the result as a
Boolean. Then in
onPostExecute I could do something with that result.
There are many ways you could approach this in RxJava. But essentially all I’m doing is creating an Observable which reports on the result of the network request. I observe the result on the main thread (with RxAndroid) so I could make any UI changes. This is effectively the same as the AsyncTask I created. The main difference is that with an Observable I have much more flexibility in how results are processed.
If You Enjoyed Reading, Please Click That Little Heart. If You Want To Read More Like This, Follow Me On Medium. Thanks!
Originally published at piercezaifman.com on May 14, 2017.