{"id":37026011,"url":"https://github.com/orange-opensource/android-activity-lifecycle","last_synced_at":"2026-01-14T03:01:08.035Z","repository":{"id":143060987,"uuid":"43939321","full_name":"Orange-OpenSource/android-activity-lifecycle","owner":"Orange-OpenSource","description":"Provide to any class a way to listen to android activity lifecycle events","archived":true,"fork":false,"pushed_at":"2015-10-15T09:43:57.000Z","size":260,"stargazers_count":4,"open_issues_count":0,"forks_count":2,"subscribers_count":16,"default_branch":"master","last_synced_at":"2025-05-07T05:04:02.593Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/Orange-OpenSource.png","metadata":{"files":{"readme":"README.MD","changelog":null,"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":"2015-10-09T07:19:35.000Z","updated_at":"2023-01-27T20:02:02.000Z","dependencies_parsed_at":"2023-03-29T20:20:51.541Z","dependency_job_id":null,"html_url":"https://github.com/Orange-OpenSource/android-activity-lifecycle","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/Orange-OpenSource/android-activity-lifecycle","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Orange-OpenSource%2Fandroid-activity-lifecycle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Orange-OpenSource%2Fandroid-activity-lifecycle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Orange-OpenSource%2Fandroid-activity-lifecycle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Orange-OpenSource%2Fandroid-activity-lifecycle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Orange-OpenSource","download_url":"https://codeload.github.com/Orange-OpenSource/android-activity-lifecycle/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Orange-OpenSource%2Fandroid-activity-lifecycle/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28408799,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T01:52:23.358Z","status":"online","status_checked_at":"2026-01-14T02:00:06.678Z","response_time":107,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":"2026-01-14T03:01:05.274Z","updated_at":"2026-01-14T03:01:07.933Z","avatar_url":"https://github.com/Orange-OpenSource.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"#Android Lifecycle\nIf you are not familiar to the lifecycle concept in android activities, please have a look [here](https://developer.android.com/training/basics/activity-lifecycle/index.html]).\n\nWhen you develop a real world application, with a lot of classes, there is a good chance that you need to do some stuff when activities' lifecycle events occur. For instance to release some resources or unregister from services when the \"on destroy\" event occurs.\n\nIt can lead to write what we call \"boiler plate\" code, since the event is notified through an [Activity](https://developer.android.com/reference/android/app/Activity.html) callback, and then you will have to forward this event to underlying objects through another mean. But let's give an example:\n\nYour activity, which receives the \"on destroy\" event:\n```java\npublic class MyActivity extends Activity {\n  private MyObject myObject;\n  ...\n  @Override\n  public void onDestroy() {\n    super.onDestroy();\n    myObject.onDestroy();\n  }\n}\n``` \nThen your object, which needs to release resources when the activity is destroyed:\n```java\nclass MyObject {\n  private Runnable runnable;\n  private Handler handler;\n  ...\n  void onDestroy() {\n    handler.removeCallbacks(runnable);\n  }\n}\n```\n\nSo here there is some room for improvment:\n- in our activity, we have to keep the ```myObject``` field only to forward the \"on destroy\" event to this object\n- in our activity, we have to override the ```onDestroy``` function only for this purpose as well\n- in our object we rely on ```MyActivity``` to provide the \"on destroy\" event\n\nIt would be great if we could break the strong link between these classes and that is the purpose of this library.\n\nWith the \"android activity lifecycle\" library, you can write:\n```java\npublic class MyActivity extends Activity {\n  // only the activity business!\n}\n``` \n```java\n// implements Lifecycle interface to receive events\nclass MyObject implements Lifecycle {\n  private Runnable runnable;\n  private Handler handler;\n  \n  MyObject(Context context) {\n    // Register for activity lifecycle events\n    // with the context, which identifies the activity\n    ApplicationLifecycle.register(this, context);\n  }\n  ...\n  @Override\n  public void onLifecycleEvent(LifecycleEvent lifecycleEvent) {\n    if (lifecycleEvent == LifecycleEvent.ON_DESTROY) {\n      // my business\n      handler.removeCallbacks(runnable);\n    }\n  }\n}\n```\n\nSo here we can see that:\n - the activity source code is cleaner, and can focus on its own business\n - the object which needs to react to activity lifecyle events can handle its business by its own\n \nWe have reduce coupling between these objects.\n\n#Build \u0026 use\nIt is a maven build, so basically ```mvn install``` should do the job. It will install the library in your local repository. You can also retrieve the jar file under the target directory (after the maven build).\n\nThe library is published on maven central to ease developers' life. So to use the library in a maven build:\n\n\u003cpre\u003e\u003ccode\u003e\u0026lt;dependency\u0026gt;\n  \u0026lt;groupId\u0026gt;com.orange.android.activitylifecycle\u0026lt;/groupId\u0026gt;\n  \u0026lt;artifactId\u0026gt;android-activity-lifecycle\u0026lt;/artifactId\u0026gt;\n  \u0026lt;version\u0026gt;0.3\u0026lt;/version\u0026gt;\n  \u0026lt;scope\u0026gt;compile\u0026lt;/scope\u0026gt;\n\u0026lt;/dependency\u0026gt;\n\u003c/pre\u003e\u003c/code\u003e\n\nIn a gradle build:\n\n\u003cpre\u003e\u003ccode\u003edependencies {\n  compile \"com.orange.android.activitylifecycle:android-activity-lifecycle:0.3\"\n}\n\u003c/pre\u003e\u003c/code\u003e\n\n#TODO\n- describe the debug api\n- describe the test app\n- extend to service/broadcast receiver/content provider specific lifecyle behaviour\n\n#Travis build\nSee [job](https://travis-ci.org/Orange-OpenSource/android-activity-lifecycle)\n\n#License\nCopyright (C) 2015 Orange\n\n[Apache License Version 2.0](https://www.apache.org/licenses/LICENSE-2.0.html)\n\n#Authors\nChristophe Maldivi \u0026 Stephane Coutant\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Forange-opensource%2Fandroid-activity-lifecycle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Forange-opensource%2Fandroid-activity-lifecycle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Forange-opensource%2Fandroid-activity-lifecycle/lists"}