You are previewing RxJava Essentials.
O'Reilly logo
RxJava Essentials

Book Description

Learn reactive programming to create awesome Android and Java apps

In Detail

RxJava—Reactive Extensions for the JVM—is a library for composing asynchronous and event-based programs using Observable sequences for the Java VM, which will help you beat Android platform limitations to create astonishing Android apps.

Starting with some quick background information on the Rx .NET library, this book quickly moves on to your first example. You will understand Observables and learn to filter, transform, or merge them in detail. Next, you will learn how to get rid of Threads, AsyncTasks, and Handlers with Schedulers to create a smooth user experience. Develop an easy, ready-to-go approach to REST API communications and enrich your skills by working with new challenging examples.

By the end of the book, you will have explored the reactive programming world and will have created your first Android app without having to think about threading, networking, concurrency, and collection management.

What You Will Learn

  • Master the Observer pattern and create Observable objects and sequences

  • Convert lists of objects to Observable sequences

  • Change existing methods to reactive asynchronous functions

  • Filter Observable sequences to ensure that only the value you want will reach your functions

  • Transform and manipulate Observable sequences into new sequences

  • Combine, merge, and concatenate Observable sequences to create new sequences

  • Move away from the Android main thread and AsyncTask to learn multithreading and concurrency the easy way with Schedulers

  • Communicate with a remote REST API using Retrofit Observable responses

  • Create your first RxJava-powered Android app

  • Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

    Table of Contents

    1. RxJava Essentials
      1. Table of Contents
      2. RxJava Essentials
      3. Credits
      4. About the Author
      5. About the Reviewer
      6. www.PacktPub.com
        1. Support files, eBooks, discount offers, and more
          1. Why subscribe?
          2. Free access for Packt account holders
      7. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Conventions
        5. Reader feedback
        6. Customer support
          1. Downloading the example code
          2. Downloading the color images of this book
          3. Errata
          4. Piracy
          5. Questions
      8. 1. RX – from .NET to RxJava
        1. Microsoft Reactive Extensions
        2. Landing in the Java world – Netflix RxJava
          1. What's different in RxJava
        3. Summary
      9. 2. Why Observables?
        1. The Observer pattern
          1. When do you use the Observer pattern?
        2. The RxJava Observer pattern toolkit
          1. Observable
            1. Hot and cold Observables
            2. Creating an Observable
              1. Observable.create()
              2. Observable.from()
              3. Observable.just()
              4. Observable.empty(), Observable.never(), and Observable.throw()
          2. Subject = Observable + Observer
            1. PublishSubject
            2. BehaviorSubject
            3. ReplaySubject
            4. AsyncSubject
        3. Summary
      10. 3. Hello Reactive World
        1. Start the engine!
          1. Dependencies
            1. RxAndroid
          2. Utils
            1. Lombok
            2. Butter Knife
            3. Retrolambda
        2. Our first Observable
        3. Creating an Observable from a list
        4. A few more examples
          1. just()
          2. repeat()
          3. defer()
          4. range()
          5. interval()
          6. timer()
        5. Summary
      11. 4. Filtering Observables
        1. Filtering a sequence
        2. Let's take what we need
          1. Take
          2. TakeLast
        3. Once and only once
          1. Distinct
          2. DistinctUntilChanged
        4. First and last
        5. Skip and SkipLast
        6. ElementAt
        7. Sampling
        8. Timeout
        9. Debounce
        10. Summary
      12. 5. Transforming Observables
        1. The *map family
          1. Map
          2. FlatMap
          3. ConcatMap
          4. FlatMapIterable
          5. SwitchMap
          6. Scan
          7. GroupBy
          8. Buffer
          9. Window
          10. Cast
        2. Summary
      13. 6. Combining Observables
        1. Merge
        2. Zip
        3. Join
        4. combineLatest
        5. And, Then, and When
        6. Switch
        7. StartWith
        8. Summary
      14. 7. Schedulers – Defeating the Android MainThread Issue
        1. StrictMode
        2. Avoiding blocking I/O operations
        3. Schedulers
          1. Schedulers.io()
          2. Schedulers.computation()
          3. Schedulers.immediate()
          4. Schedulers.newThread()
          5. Schedulers.trampoline()
        4. Nonblocking I/O operations
        5. SubscribeOn and ObserveOn
        6. Handling a long task
        7. Executing a network task
        8. Summary
      15. 8. REST in Peace – RxJava and Retrofit
        1. The project goal
        2. Retrofit
        3. The app structure
          1. Creating the Activity class
          2. Creating the RecyclerView adapter
            1. Retrieving the weather forecast
            2. Opening the website
        4. Summary
      16. Index