GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - aomari/RxJavaInterval

BranchesTags
Open more actions menu

Latest commit

 

History

2 Commits
2 Commits

Folders and files

NameName
Last commit message
Last commit date
.idea
.idea
 
 
app
app
 
 
gradle/wrapper
gradle/wrapper
 
 
.gitignore
.gitignore
 
 
README.md
README.md
 
 
build.gradle
build.gradle
 
 
gradle.properties
gradle.properties
 
 
gradlew
gradlew
 
 
gradlew.bat
gradlew.bat
 
 
settings.gradle
settings.gradle
 
 

Repository files navigation

AndroidRxJava-Interval

Android RxJava, how to start, stop, reset Observable.interval programmatically on run time!

Android RxJava Interval: Sample App

AmjadOmari

In this sample app, we are creating a class that is triggering an event each n time, in addition we have added useful methods to the class, that will allow as to use it smoothly.

  1. setPeriod(int period): this method set the ticks period in seconds.
  2. start(): this mithod to start the observable.interval forever.
  3. stop(): to stop the observable.interval.
  4. setOnTickListener(OnTickListener onTickListener): listener method that will be called in heach tick.

Expectation:

to understand this samble, you should have a knowledge of:

  1. Java programming and Android.
  2. Java 8 lambda expressions.
  3. have a good knowledge of using Butterknife library.

This is a Samble app that is connecting to Nasa rest API service to get data and display it in a list view. This App aims to present of how to build a clean code using Dagger 2 and MVP structure.


This app has been designed in such a way to describe how to use the reactive programming (Observable.interval) using RxJava and butterknife.

Observable.interval

 subscription = Observable.interval(period, TimeUnit.MILLISECONDS)
                    .subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(aLong -> {
                        onTickListener.onTick();
                    });

As you see, Observable.interval takes two parameters

  1. Period: the period between each tick
  2. Unit time and this code be in MILLISECONDS, SECONDS, DAYS, HOURS, MICROSECONDS, NANOSECONDS, and MINUTS.

Take care the ObserveOn will not run on UI thread if you did not pass AndroidSchedulers.mainThread

observeOn(AndroidSchedulers.mainThread())

and on each tick, the observer will call: subscribe(aLong -> { //do what ever you want here... });

To Stop the Disposable interval:To Stop the Disposable interval:

if (subscription != null && !subscription.isDisposed()) {
            subscription.dispose();
        }

Library reference resources:

  1. RxJava2: https://github.com/amitshekhariitbhu/RxJava2-Android-Samples
  2. ButterKnife: http://jakewharton.github.io/butterknife/
  3. Lambda: https://guides.codepath.com/android/Lambda-Expressions

Concept reference resources:

  1. RxJava + Fast Android Networking
  2. Migrating from RxJava 1.0 to RxJava 2.0 and Learn RxJava by Examples
  3. RxJava Anatomy: What is RxJava, how RxJava is designed, and how RxJava works.

aomari open source projects

Check out amjadomari awesome open source projects here

Contributing to Android RxJava2 Architecture

Just make pull request. You are in!

About

No description or website provided.

Topics

androidandroid-appandroid-applicationandroid-developmentandroid-studioandroid-uiandroidstudiolambdalambda-expressionsreactive-programmingrxjavarxjava-2rxjava-androidrxjava2

Resources

Readme
Activity

Stars

0 stars

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.