AndroidAutoDispose

Easy way to auto dispose with android lifecycle event.

License

License

Categories

Categories

Auto Application Layer Libs Code Generators
GroupId

GroupId

com.github.ykrank
ArtifactId

ArtifactId

androidautodispose
Last Version

Last Version

0.4.0
Release Date

Release Date

Type

Type

aar
Description

Description

AndroidAutoDispose
Easy way to auto dispose with android lifecycle event.
Project URL

Project URL

https://github.com/ykrank/AndroidAutoDispose/
Source Code Management

Source Code Management

https://github.com/ykrank/AndroidAutoDispose/

Download androidautodispose

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.ykrank/androidautodispose/ -->
<dependency>
    <groupId>com.github.ykrank</groupId>
    <artifactId>androidautodispose</artifactId>
    <version>0.4.0</version>
    <type>aar</type>
</dependency>
// https://jarcasting.com/artifacts/com.github.ykrank/androidautodispose/
implementation 'com.github.ykrank:androidautodispose:0.4.0'
// https://jarcasting.com/artifacts/com.github.ykrank/androidautodispose/
implementation ("com.github.ykrank:androidautodispose:0.4.0")
'com.github.ykrank:androidautodispose:aar:0.4.0'
<dependency org="com.github.ykrank" name="androidautodispose" rev="0.4.0">
  <artifact name="androidautodispose" type="aar" />
</dependency>
@Grapes(
@Grab(group='com.github.ykrank', module='androidautodispose', version='0.4.0')
)
libraryDependencies += "com.github.ykrank" % "androidautodispose" % "0.4.0"
[com.github.ykrank/androidautodispose "0.4.0"]

Dependencies

compile (4)

Group / Artifact Type Version
io.reactivex.rxjava2 : rxjava jar 2.1.1
io.reactivex.rxjava2 : rxandroid jar 2.0.1
com.uber.autodispose : autodispose jar 0.2.0
com.github.ykrank : androidlifecycle jar 0.4.0

Project Modules

There are no modules declared in this project.

AndroidAutoDispose

中文说明

Easy way to auto dispose rxjava2 with android lifecycle event

AndroidLifeCycle is an android tool for auto dippose rxjava2 disposable when target android lifecycle event arrive.

Overview

Work with AndroidLifecycle and AutoDispose, auto dispose with bound fragment, activity, context or view lifecycle event.

Motivations

Lifecycle management with RxJava and Android is nothing new, so why yet another tool? You can see this in uber AutoDispose readme #Motivations. In short, you should add disposable manually, or use RxLifecycle. Previous not elegant. To use RxLifecycle correct, compose() needed to be as close to the subscribe() call as possible to properly wrap upstream. And Single or Completable dispose always throw CancellationException, you should always remember handle it. This limit make it was risky to use (particularly in a large team with varying levels of RxJava experience). But in this library, you can only listen event at flow last, you can also register global outsideLifecycleExcepitonHandler by AutoDisposePlugins.setOutsideLifecycleHandler, ignore lots of risk.

Usage

Bind myObservable with myFragment destroy event

myObservable
    .doStuff()
    .to(AndroidRxDispose.withObservable(myFragment, FragmentEvent.DESTROY))   // The scope
    .subscribe(s -> ...);

Bind mySingle with myView attached activity pause event

mySingle
    .doStuff()
    .to(AndroidRxDispose.withSingle(myView, ViewEvent.PAUSE))   // The scope
    .subscribe(s -> ...);

Bind myCompletable with myView attached fragment stop event

AndroidLifeCycle.bindFragment(myView, myFragment);

myCompletable
    .doStuff()
    .to(AndroidRxDispose.withCompletable(myView, ViewEvent.STOP))   // The scope
    .subscribe(s -> ...);

Support Rxjava2 Observable, Single, Completable, Maybe, Flowable

Download

Maven Central

compile 'com.github.ykrank:androidautodispose:x.y.z'

License

Copyright (C) 2017 Yk Rank

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.

Versions

Version
0.4.0
0.3.0