{"id":29308537,"url":"https://github.com/jzallas/lifecycleaware","last_synced_at":"2025-07-07T07:12:34.110Z","repository":{"id":57725805,"uuid":"105827551","full_name":"jzallas/LifecycleAware","owner":"jzallas","description":"Annotation based triggers that automatically hook observers into the Android lifecycle.","archived":false,"fork":false,"pushed_at":"2017-10-10T05:22:51.000Z","size":219,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-16T12:59:16.295Z","etag":null,"topics":["android","android-architecture-components","android-lifecycle","annotation-processing","lifecycle"],"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/jzallas.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-10-04T22:55:01.000Z","updated_at":"2024-04-16T12:59:16.295Z","dependencies_parsed_at":"2022-09-02T03:31:05.435Z","dependency_job_id":null,"html_url":"https://github.com/jzallas/LifecycleAware","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/jzallas/LifecycleAware","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jzallas%2FLifecycleAware","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jzallas%2FLifecycleAware/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jzallas%2FLifecycleAware/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jzallas%2FLifecycleAware/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jzallas","download_url":"https://codeload.github.com/jzallas/LifecycleAware/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jzallas%2FLifecycleAware/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264032310,"owners_count":23546809,"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","android-architecture-components","android-lifecycle","annotation-processing","lifecycle"],"created_at":"2025-07-07T07:12:33.199Z","updated_at":"2025-07-07T07:12:34.098Z","avatar_url":"https://github.com/jzallas.png","language":"Java","readme":"LifecycleAware\n============\n\n[![CircleCI](https://circleci.com/gh/jzallas/LifecycleAware/tree/master.svg?style=shield)](https://circleci.com/gh/jzallas/LifecycleAware/tree/master)\n\nAnnotation based triggers that automatically hook observers into the Android lifecycle.\n\n * Pick and choose different lifecycle events for each annotated observer\n * Leverages `android.arch.lifecycle` components and is compatible with the very same `Lifecycle.Event`s\n * Automatic binding in one step\n * Works out of the box with `Activity` and `Fragment` classes\n\nGetting Started\n---------------\n##### Marking your Observers\nIn order to properly facilitate auto binding, your observers need two things:\n 1. Your observers needs to implement `LifecycleEventObserver`\n 3. Your observers needs to be initialized before you call `LifecycleBinder.bind(...)`\n\nOnce you meet those prerequisites, you can tag any of your observers like this:\n\n```java\npublic class MyActivity extends AppCompatActivity {\n  // myObserver will automatically trigger during onStart(...)\n  @LifecycleAware(Lifecycle.Event.ON_START)\n  LifecycleEventObserver myObserver = new MyObserver();\n\n  @Override\n  protected void onCreate(Bundle savedInstanceState) {\n      super.onCreate(savedInstanceState);\n      // bind all observers to this Activity's lifecycle\n      LifecycleBinder.bind(this);\n  }\n}\n```\n##### Method based Observers\nIt is possible quickly register _any_ variable as `LifecycleAware` as long as you provide the method that should be called during the lifecycle event.\n\n```java\n// myList will automatically clear() during onResume(...)\n@LifecycleAware(value = Lifecycle.Event.ON_RESUME, method = \"clear\")\nList\u003cString\u003e myList = new ArrayList\u003c\u003e();\n```\n\n##### Custom Targets\nIn the case that your target class is not a core Android component (ie not an `Activity`),\nyou can still perform auto binding. You just need to properly provide the target when binding:\n\n```java\nclass MyTarget {\n  @LifecycleAware(Lifecycle.Event.ON_DESTROY)\n  LifecycleEventObserver observer = new MyObserver();\n}\n\nMyTarget myTarget = new MyTarget();\nLifecycleBinder.bind(myTarget, MyActivity.this);\n```\n\n##### Custom Lifecycles\nIn the case that your `Lifecycle` is customized, you can still perform auto binding.\nYou just need to properly provide the `LifecycleOwner` or `Lifecycle` when binding:\n\n```java\nLifecycleBinder.bind(someTarget, myCustomOwner);\n// or\nLifecycleBinder.bind(someTarget, myCustomLifecycle);\n```\n\nSamples\n-------\nYou can find examples in the included [sample app](/sample-app).\n\nDependencies\n------------\n```groovy\ndependencies {\n    implementation 'com.jzallas:lifecycleaware:0.1.0'\n    annotationProcessor 'com.jzallas:lifecycleaware-compiler:0.1.0'\n}\n```\n\nLicense\n-------\n\n    Copyright 2017 Jon Zallas\n\n    Licensed under the Apache License, Version 2.0 (the \"License\");\n    you may not use this file except in compliance with the License.\n    You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n    Unless required by applicable law or agreed to in writing, software\n    distributed under the License is distributed on an \"AS IS\" BASIS,\n    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n    See the License for the specific language governing permissions and\n    limitations under the License.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjzallas%2Flifecycleaware","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjzallas%2Flifecycleaware","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjzallas%2Flifecycleaware/lists"}