RxAppState RxJava Adapter

A simple Android library that monitors app state changes (background / foreground).

Лицензия

Лицензия

Категории

Категории

RxJava Контейнер Микросервисы Reactive libraries
Группа

Группа

com.jenzz.appstate
Идентификатор

Идентификатор

adapter-rxjava
Последняя версия

Последняя версия

3.0.1
Дата

Дата

Тип

Тип

aar
Описание

Описание

RxAppState RxJava Adapter
A simple Android library that monitors app state changes (background / foreground).
Ссылка на сайт

Ссылка на сайт

https://github.com/jenzz/RxAppState
Система контроля версий

Система контроля версий

https://github.com/jenzz/RxAppState

Скачать adapter-rxjava

Как подключить последнюю версию

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

Зависимости

compile (2)

Идентификатор библиотеки Тип Версия
com.android.support » support-annotations jar 25.3.1
io.reactivex : rxjava jar 1.3.0

Модули Проекта

Данный проект не имеет модулей.

DEPRECATED

RxAppState is deprecated. No more development will be taking place.

Use Google's ProcessLifecycleOwner instead which is part of Android Architecture Components.

An implementation can be as simple as:

public class AppLifecycleListener implements LifecycleObserver {

    @OnLifecycleEvent(Lifecycle.Event.ON_START)
    public void onAppDidEnterForeground() {
        // ...
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_STOP)
    public void onAppDidEnterBackground() {
       // ...
    }
}

Register the observer like this:

ProcessLifecycleOwner.get().getLifecycle().addObserver(new AppLifecycleListener());

Here is a great blog post that explains it in more detail: Detecting when an Android app backgrounds in 2018

RxAppState Build Status

A simple, reactive Android library based on RxJava that monitors app state changes.
It notifies subscribers every time the app goes into background and comes back into foreground.

A typical use case is, for example, session tracking for analytics purposes or suppressing push notifications when the app is currently visible to the user.

Background

Android has this ancient pain of not providing any type of callback to know if your app is currently in the foreground or background. It is lacking an equivalent of the iOS UIApplicationDelegate which offers callbacks like applicationDidEnterBackground and applicationDidBecomeActive.

There are two popular discussions on this topic on StackOverflow:

This library internally uses a combination of ActivityLifecycleCallbacks and the onTrimMemory(int level) callback to identify the current app state.
Just check out the source code (mainly: DefaultAppStateRecognizer). The implementation is dead simple.

Usage

You most probably want to monitor for app state changes in your application's onCreate() method in which case you also don't need to worry about unregistering your AppStateListener. Remember that if you subscribe in an Activity or a Fragment, don't forget to unsubscribe to avoid memory leaks.

AppStateMonitor appStateMonitor = RxAppStateMonitor.create(this);
appStateMonitor.addListener(new AppStateListener() {
    @Override
    public void onAppDidEnterForeground() {
        // ...
    }

    @Override
    public void onAppDidEnterBackground() {
        // ...
    }
});
appStateMonitor.start();

Example

Check out the sample project for an example implementation.

Download

Grab it via Gradle:

dependencies {
  compile 'com.jenzz.appstate:appstate:3.0.1'
}

Note: There are adapters available for RxJava and RxJava2.

License

This project is licensed under the MIT License.

Версии библиотеки

Версия
3.0.1
3.0.0