{"id":18007008,"url":"https://github.com/shiraji/butai","last_synced_at":"2025-07-04T07:05:16.407Z","repository":{"id":150154487,"uuid":"80118905","full_name":"shiraji/butai","owner":"shiraji","description":"Android library that adds methods isForeground/isBackground/isReturnedFromBackground","archived":false,"fork":false,"pushed_at":"2017-01-31T13:57:41.000Z","size":125,"stargazers_count":16,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-07T12:05:35.841Z","etag":null,"topics":["android-library","java","kotlin"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shiraji.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-01-26T13:56:13.000Z","updated_at":"2022-04-24T13:41:41.000Z","dependencies_parsed_at":"2023-04-08T09:33:01.903Z","dependency_job_id":null,"html_url":"https://github.com/shiraji/butai","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/shiraji/butai","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shiraji%2Fbutai","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shiraji%2Fbutai/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shiraji%2Fbutai/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shiraji%2Fbutai/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shiraji","download_url":"https://codeload.github.com/shiraji/butai/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shiraji%2Fbutai/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263464185,"owners_count":23470473,"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":["android-library","java","kotlin"],"created_at":"2024-10-30T01:11:36.898Z","updated_at":"2025-07-04T07:05:16.382Z","avatar_url":"https://github.com/shiraji.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# butai\n\nbutai is Android library that adds functions return the application is in foreground, background or return from background.\n\nbutai is inspired by [@yshrsmz](https://github.com/yshrsmz)'s [blog entry](http://yslibrary.net/2015/07/30/android_how_to_detect_app_is_background_or_not/) (in Japanese).\n\nThe main logic of this library is that butai counts up the number of running Activities using `Application#ActivityLifecycleCallbacks`. Based on the sum of running Activities, `Butai` interface provides that the application is in foreground/background.\n\n# Prerequisite\n\n* minSdk must be higher than 14 (because of `Application#ActivityLifecycleCallbacks`)\n* Only one of Java/Kotlin implementation can be used. Not both of them\n\n# How to install \u0026 setup?\n\nbutai has [Java](library-java) and [Kotlin](library) implementations. Each has different steps to install and setup.\n\nPlease read each README.\n\n* [Java](library-java/README.md)\n* [Kotlin](library/README.md)\n\n# What the app status can get?\n\n`Butai` interface has following method signatures in kotlin.\n\n```kotlin\nfun isReturnedFromBackground(): Boolean\nfun isBackground(): Boolean\nfun isForeground(): Boolean\n```\n\n* `isReturnedFromBackground()` true if the app shows up to foreground, false otherwise. This is true until other Activity launch or kill the Activity.\n* `isBackground()` true if the app go to background, false otherwise.\n* `isForeground()` true if the app is on foreground, false otherwise.\n\n# How to get the app status?\n\n`MyApplication` class above delegate these methods using Class Delegation.\n\n```kotlin\nclass MainAktivity : AppCompatActivity() {\n\n    override fun onStart() {\n        super.onStart()\n        if ((application as MyApplication).isForeground()) Log.d(\"MainAktivity\", \"App is foreground\")\n        if ((application as MyApplication).isReturnedFromBackground()) Log.d(\"MainAktivity\", \"App returns from background\")\n    }\n\n    override fun onStop() {\n        super.onStop()\n        if ((application as MyApplication).isForeground()) Log.d(\"MainAktivity\", \"App is still foreground\")\n        if ((application as MyApplication).isBackground()) Log.d(\"MainAktivity\", \"App goes to background\")\n    }\n\n}\n```\n\n# License\n\n```\nCopyright 2017 Yoshinori Isogai\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n   http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshiraji%2Fbutai","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshiraji%2Fbutai","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshiraji%2Fbutai/lists"}