All Projects → florent37 → Rxlifecycle

florent37 / Rxlifecycle

Licence: apache-2.0
Rx binding of stock Android Activities & Fragment Lifecycle, avoiding memory leak

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Rxlifecycle

Rxbus
Android reactive event bus that simplifies communication between Presenters, Activities, Fragments, Threads, Services, etc.
Stars: ✭ 79 (-39.69%)
Mutual labels:  rxjava, rxjava2, activity, fragment
Thirtyinch
a MVP library for Android favoring a stateful Presenter
Stars: ✭ 1,052 (+703.05%)
Mutual labels:  rxjava, rxjava2, activity, fragment
RxComponentLifecycle
Rx binding of new Android Architecture Component Lifecycle
Stars: ✭ 57 (-56.49%)
Mutual labels:  observable, fragment, activity, lifecycle
Disposer
Easily dispose rxJava streams with Android's Lifecycle
Stars: ✭ 176 (+34.35%)
Mutual labels:  rxjava, rxjava2, lifecycle
Rxretrojsoup
A simple API-like from html website (scrapper) for Android, RxJava2 ready !
Stars: ✭ 492 (+275.57%)
Mutual labels:  rxjava, rxjava2, observable
AppListManager
📱 AppListManager (Android Library) makes managing application and activity lists easy.
Stars: ✭ 59 (-54.96%)
Mutual labels:  memory, activity, leak
RxAnimator
An RxJava2 binding for android Animator
Stars: ✭ 80 (-38.93%)
Mutual labels:  rxjava, observable, rxjava2
Mvvmhabit
goldze: 本人喜欢尝试新的技术,以后发现有好用的东西,我将会在企业项目中实战,没有问题了就会把它引入到MVVMHabit中,一直维护着这套框架,谢谢各位朋友的支持。如果觉得这套框架不错的话,麻烦点个 star,你的支持则是我前进的动力!
Stars: ✭ 6,789 (+5082.44%)
Mutual labels:  rxjava, rxjava2, lifecycle
Tdcapp
Sample app which access the TDC (The Developer's Conference) REST API.
Stars: ✭ 55 (-58.02%)
Mutual labels:  rxjava2, lifecycle
S Mvp
🔥🔥优化版MVP,使用注解泛型简化代码编写,使用模块化协议方便维护,APT过程使用注解解析器利用JavaPoet🌝完成重复模块的编写,利用ASpect+GradlePlugin 完成横向AOP编程+Javassist动态字节码注入+Tinker实现热修复+Retrofit实现优雅网络操作+RxJava轻松玩转数据处理
Stars: ✭ 1,095 (+735.88%)
Mutual labels:  rxjava, lifecycle
Okhttp Okgo
OkGo - 3.0 震撼来袭,该库是基于 Http 协议,封装了 OkHttp 的网络请求框架,比 Retrofit 更简单易用,支持 RxJava,RxJava2,支持自定义缓存,支持批量断点下载管理和批量上传管理功能
Stars: ✭ 10,407 (+7844.27%)
Mutual labels:  rxjava, rxjava2
Nuxt Memwatch
Quickly watch real-time memory stats of your nuxt app
Stars: ✭ 76 (-41.98%)
Mutual labels:  memory, leak
Rxjavaapp
学习RxJava操作符的APP,新增RxJava2.x介绍
Stars: ✭ 1,049 (+700.76%)
Mutual labels:  rxjava, rxjava2
Navigator
Android Multi-module navigator, trying to find a way to navigate into a modularized android project
Stars: ✭ 131 (+0%)
Mutual labels:  activity, fragment
Bigbang
Android base project used by Xmartlabs team
Stars: ✭ 47 (-64.12%)
Mutual labels:  rxjava, rxjava2
Graphql Retrofit Converter
A Retrofit 2 Converter.Factory for GraphQL.
Stars: ✭ 46 (-64.89%)
Mutual labels:  rxjava, rxjava2
Aiyagirl
🔥 爱吖妹纸(含 Kotlin 分支版本)——Retrofit + RxJava + MVP 架构 APP 体验代码家的干货集中营 Gank.io,福利多多,不容错过
Stars: ✭ 1,109 (+746.56%)
Mutual labels:  rxjava, rxjava2
Freesound Android
Unofficial Android client for the Freesound Project
Stars: ✭ 81 (-38.17%)
Mutual labels:  rxjava, rxjava2
Neteasecloudmusic Mvvm
Jetpack MVVM最佳实践 - 重构仿网易云音乐安卓客户端
Stars: ✭ 103 (-21.37%)
Mutual labels:  lifecycle, fragment
Mvpframes
整合大量主流开源项目并且可高度配置化的 Android MVP 快速集成框架,支持 AndroidX
Stars: ✭ 100 (-23.66%)
Mutual labels:  rxjava, rxjava2

RxLifecycle

Rx binding of stock Android Activities & Fragment Lifecycle, avoiding memory leak

This library allows one to automatically finish sequences based on Android lifecycle state, This capability is useful in Android, where incomplete subscriptions can cause memory leaks.

You don't need to extends Activity or Fragment

Compatible with all RxJava2 types : Single, Observable, Flowable, Maybe, Completable

mywebservice.searchUsers("florent")
            .observeOn(AndroidSchedulers.mainThread())
            .subscribeOn(Schedulers.io())
            
            //will dispose this call when the activity / fragment destroys
            .compose(disposeOnDestroy(getLifecycle()))
            
            .subscribe(users -> {
                //display users with animation
            });

Buy Me a Coffee at ko-fi.com

Download

dependencies {
    implementation 'com.github.florent37:rxlifecycle:(lastversion)'
}

Listen to activity / fragment lifecycle events

RxLifecycle.with(this)
           .onDestroy()
           .subscribe(event -> 
                /*do what you had to do on view destroy*/
            );
            
RxLifecycle.with(getLifeCycle())
           .onResume()
           .subscribe(event -> 
                /*do what you had to do on view resume*/
            );

Available events :

  • .onCreate()
  • .onStart()
  • .onResume()
  • .onPause()
  • .onStop()
  • .onDestroy()

Automatically Dispose Rx Observables

You can dispose an Rx operation when the activity state changes, for example

Using doOnSubscribe

mywebservice.searchUsers("florent")
            .doOnSubscribe(disposable -> disposeOnDestroyed(this, disposable)
            .subscribe(l -> 
                 ...
            });

Using compose

//With `import static florent37.github.com.rxlifecycle.RxLifecycle.disposeOnDestroyed;`

mywebservice.searchUsers("florent")
            .compose(disposeOnDestroy(this))
            .subscribe(l -> 
                 ...
            });

Availables : disposeOnStop, disposeOnPause, etc...

You can also use enum state

mywebservice.searchUsers("florent")
            .doOnSubscribe(disposable -> disposeOn(this, DESTROY, disposable)
            .subscribe(l -> 
                 ...
            });

Wait until an Activity state

You can pause an Rx chain until it's not on an event, for example wait for activity to be resumed to perform an animation

mywebservice.searchUsers("florent")
          
            //will pause
            .flatMap(value -> onlyIfResumedOrStarted(this, value))
          
            //only if resumed
            .subscribe(value -> 
                 ...
            });

Usage with MVP

You can bind easily your presenter with a lifecycle, example :

public abstract class AbstractPresenter<V extends AbstractPresenter.View> {

    private WeakReference<V> viewReference;

    @CallSuper
    public void bind(LifecycleOwner lifecycleOwner, V view) {
        this.viewReference = new WeakReference<V>(view);

        RxLifecycle.with(lifecycleOwner)
                .onStart()
                .distinct() //once
                .subscribe(x -> start());
    }

    public abstract void start();

    private interface View {

    }
}

Credits

Author: Florent Champigny

Blog : http://www.tutos-android-france.com/

Android app on Google Play Follow me on Google+ Follow me on Twitter Follow me on LinkedIn

License

Copyright 2017 Florent37, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].