{"id":18270124,"url":"https://github.com/jenzz/RxAppState","last_synced_at":"2025-04-04T23:31:44.528Z","repository":{"id":57725583,"uuid":"53265801","full_name":"jenzz/RxAppState","owner":"jenzz","description":"[DEPRECATED] A simple Android library that monitors app state changes (background / foreground).","archived":true,"fork":false,"pushed_at":"2018-07-02T08:17:52.000Z","size":297,"stargazers_count":195,"open_issues_count":7,"forks_count":20,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-01-13T09:42:58.082Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jenzz.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-03-06T16:58:22.000Z","updated_at":"2024-05-28T01:25:34.000Z","dependencies_parsed_at":"2022-09-13T08:41:17.888Z","dependency_job_id":null,"html_url":"https://github.com/jenzz/RxAppState","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jenzz%2FRxAppState","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jenzz%2FRxAppState/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jenzz%2FRxAppState/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jenzz%2FRxAppState/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jenzz","download_url":"https://codeload.github.com/jenzz/RxAppState/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247266476,"owners_count":20910831,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-05T11:38:19.078Z","updated_at":"2025-04-04T23:31:43.797Z","avatar_url":"https://github.com/jenzz.png","language":"Java","readme":"DEPRECATED\n==========\nRxAppState is deprecated. No more development will be taking place.\n\nUse Google's [ProcessLifecycleOwner](https://developer.android.com/reference/android/arch/lifecycle/ProcessLifecycleOwner) instead\nwhich is part of [Android Architecture Components](https://developer.android.com/topic/libraries/architecture).\n\nAn implementation can be as simple as:\n```java\npublic class AppLifecycleListener implements LifecycleObserver {\n\n    @OnLifecycleEvent(Lifecycle.Event.ON_START)\n    public void onAppDidEnterForeground() {\n        // ...\n    }\n\n    @OnLifecycleEvent(Lifecycle.Event.ON_STOP)\n    public void onAppDidEnterBackground() {\n       // ...\n    }\n}\n```\nRegister the observer like this:\n```java\nProcessLifecycleOwner.get().getLifecycle().addObserver(new AppLifecycleListener());\n```\n\nHere is a great blog post that explains it in more detail:\n[Detecting when an Android app backgrounds in 2018](https://proandroiddev.com/detecting-when-an-android-app-backgrounds-in-2018-4b5a94977d5c)\n\nRxAppState [![Build Status](https://travis-ci.org/jenzz/RxAppState.svg?branch=master)](https://travis-ci.org/jenzz/RxAppState)\n==========\nA simple, reactive Android library based on [RxJava](https://github.com/ReactiveX/RxJava) that monitors app state changes.  \nIt notifies subscribers every time the app goes into background and comes back into foreground.\n\nA typical use case is, for example, session tracking for analytics purposes\nor suppressing push notifications when the app is currently visible to the user.\n\nBackground\n----------\nAndroid has this ancient pain of not providing any type of callback to know if your app is currently in the foreground or background.\nIt is lacking an equivalent of the iOS [UIApplicationDelegate](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplicationDelegate_Protocol)\nwhich offers callbacks like [`applicationDidEnterBackground`](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplicationDelegate_Protocol/#//apple_ref/occ/intfm/UIApplicationDelegate/applicationDidEnterBackground:)\nand [`applicationDidBecomeActive`](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplicationDelegate_Protocol/#//apple_ref/occ/intfm/UIApplicationDelegate/applicationDidBecomeActive:).\n\nThere are two popular discussions on this topic on StackOverflow:\n\n* [How to detect when an Android app goes to the background and come back to the foreground](http://stackoverflow.com/questions/4414171/how-to-detect-when-an-android-app-goes-to-the-background-and-come-back-to-the-fo)\n* [Checking if an Android application is running in the background](http://stackoverflow.com/questions/3667022/checking-if-an-android-application-is-running-in-the-background)\n\nThis library internally uses a combination of `ActivityLifecycleCallbacks` and the `onTrimMemory(int level)` callback to identify the current app state.  \nJust check out the source code (mainly: [DefaultAppStateRecognizer](https://github.com/jenzz/RxAppState/blob/master/appstate/src/main/java/com/jenzz/appstate/internal/DefaultAppStateRecognizer.java)).\nThe implementation is dead simple.\n\nUsage\n-----\nYou most probably want to monitor for app state changes in your application's `onCreate()` method\nin which case you also don't need to worry about unregistering your `AppStateListener`.\nRemember that if you subscribe in an `Activity` or a `Fragment`, don't forget to unsubscribe to avoid memory leaks.\n```java\nAppStateMonitor appStateMonitor = RxAppStateMonitor.create(this);\nappStateMonitor.addListener(new AppStateListener() {\n    @Override\n    public void onAppDidEnterForeground() {\n        // ...\n    }\n\n    @Override\n    public void onAppDidEnterBackground() {\n        // ...\n    }\n});\nappStateMonitor.start();\n```\n\nExample\n-------\nCheck out the [sample project](https://github.com/jenzz/RxAppState/tree/master/sample) for an example implementation.\n\nDownload\n--------\nGrab it via Gradle:\n\n```groovy\ndependencies {\n  compile 'com.jenzz.appstate:appstate:3.0.1'\n}\n```\n\n**Note:** There are adapters available for [RxJava](https://github.com/jenzz/RxAppState/tree/master/appstate-adapters/rxjava) and [RxJava2](https://github.com/jenzz/RxAppState/tree/master/appstate-adapters/rxjava2).\n\nLicense\n-------\nThis project is licensed under the [MIT License](https://raw.githubusercontent.com/jenzz/RxAppState/master/LICENSE).","funding_links":[],"categories":["etc"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjenzz%2FRxAppState","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjenzz%2FRxAppState","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjenzz%2FRxAppState/lists"}