{"id":36417007,"url":"https://github.com/simonpercic/aircycle","last_synced_at":"2026-01-11T17:00:06.346Z","repository":{"id":57722807,"uuid":"67951194","full_name":"simonpercic/AirCycle","owner":"simonpercic","description":"Flexible binding of Android Activity lifecycle callbacks to fields","archived":false,"fork":false,"pushed_at":"2016-10-18T13:18:39.000Z","size":225,"stargazers_count":47,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2023-07-26T22:07:51.436Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/simonpercic.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-09-11T19:57:25.000Z","updated_at":"2019-08-02T09:46:36.000Z","dependencies_parsed_at":"2022-08-28T08:41:13.596Z","dependency_job_id":null,"html_url":"https://github.com/simonpercic/AirCycle","commit_stats":null,"previous_names":[],"tags_count":3,"template":null,"template_full_name":null,"purl":"pkg:github/simonpercic/AirCycle","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonpercic%2FAirCycle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonpercic%2FAirCycle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonpercic%2FAirCycle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonpercic%2FAirCycle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simonpercic","download_url":"https://codeload.github.com/simonpercic/AirCycle/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonpercic%2FAirCycle/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28314253,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-11T14:58:17.114Z","status":"ssl_error","status_checked_at":"2026-01-11T14:55:53.580Z","response_time":60,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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-11T17:00:06.119Z","updated_at":"2026-01-11T17:00:06.302Z","avatar_url":"https://github.com/simonpercic.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AirCycle \n\nBinds Android Activity lifecycle callbacks to Activity fields annotated with `@AirCycle`. \n\n[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-AirCycle-brightgreen.svg?style=flat)](http://android-arsenal.com/details/1/4537)\n[![CircleCI](https://circleci.com/gh/simonpercic/AirCycle.svg?style=shield\u0026circle-token=1577d7f1180e6fae96a2ec83b8c7302111bdca9e)](https://circleci.com/gh/simonpercic/AirCycle)\n[ ![Download](https://api.bintray.com/packages/simonpercic/maven/aircycle/images/download.svg) ](https://bintray.com/simonpercic/maven/aircycle/_latestVersion)\n[![Method count](https://img.shields.io/badge/Methods count-core: 2 | deps: 109-e91e63.svg)](http://www.methodscount.com/?lib=com.github.simonpercic%3Aaircycle%3A1.2.0)\n\nFields annotated with `@AirCycle` that are defined in an Activity will receive lifecycle callbacks of the enclosing Activity. \nThe Activity does NOT need to implement any interface or extend any specific base class.\n\nThe field itself also does NOT need to implement any interface or extend any specific base class.\n\nThe binding class is generated in compile time using Java annotation processing, NO reflection is used at runtime.\n\n\n## Usage\n\n```java\npublic class MyActivity extends AppCompatActivity {\n\n    @AirCycle LifecycleListener myListener;\n\n    @Override\n    protected void onCreate(Bundle savedInstanceState) {\n        MyActivityAirCycle.bind(this); // generated by the AirCycle annotation processor\n        super.onCreate(savedInstanceState);\n        setContentView(R.layout.activity_my);\n        \n        myListener = new LifecycleListener();\n    }\n}\n```\n\n```java\npublic class LifecycleListener {\n\n    // no arguments \n    public void onCreate() {\n        // The bound MyActivity was created\n    }\n\n    // can also pass the Activity\n    public void onCreate(MyActivity activity) {\n        // The bound MyActivity was created\n    }\n\n    // or just a Bundle \n    public void onCreate(Bundle bundle) {\n        // The bound MyActivity was created\n    }\n\n    // ...\n\n    // ActivityLifecycleCallbacks method naming is also supported\n    public void onActivityDestroyed(AppCompatActivity activity, Bundle bundle) {\n        // The bound MyActivity was destroyed\n    }\n\n    // can pass the base Activity as well\n    public void onDestroy(AppCompatActivity activity) {\n        // The bound MyActivity was destroyed\n    }\n    \n    // arguments order does not matter in listener methods\n    public void onDestroy(Bundle bundle, AppCompatActivity activity) {\n        // The bound MyActivity was destroyed\n    }\n}\n```\n\nAirCycle annotation processor will generate a binding class for the Activity, named \u0026lt;YourActivity\u0026gt;AirCycle with a static `bind` method.\n\nYou **MUST** call `MyActivityAirCycle.bind(this)` BEFORE calling `super.onCreate(savedInstanceState)`, otherwise the bound listener will NOT receive the first onCreate call for the Activity.\n\n## Activity lifecycle callbacks\n\nThe following [Activity lifecycle callbacks](https://developer.android.com/reference/android/app/Application.ActivityLifecycleCallbacks.html) are supported:\n\n- onCreate() (with optional *Bundle savedInstanceState* argument)\n- onStart()\n- onResume()\n- onPause()\n- onStop()\n- onSaveInstanceState() (with optional *Bundle outState* argument)\n- onDestroy()\n\n\n## Listener\n\nFields annotated with `@AirCycle` can be plain Java classes or interfaces (POJOs) that have public lifecycle callback methods. \nMethod name defines the bound Activity lifecycle callback.\n\n lifecycle callback   | listener method      | alternative listener method  | optional Bundle arg?\n----------------------|----------------------|------------------------------|--------------------------\nonCreate()            |onCreate()            |onActivityCreated()           | \u0026#10003;\nonStart()             |onStart()             |onActivityStarted()           | -\nonResume()            |onResume()            |onActivityResumed()           | -\nonPause()             |onPause()             |onActivityPaused()            | -\nonStop()              |onStop()              |onActivityStopped()           | -\nonSaveInstanceState() |onSaveInstanceState() |onActivitySaveInstanceState() | \u0026#10003;\nonDestroy()           |onDestroy()           |onActivityDestroyed()         | -\n\n**ALL** listener methods can optionally have the bound Activity instance as the method argument.\nUnlike method names, argument names do NOT matter.\n\n\n#### Listener callbacks\nListener callbacks are invoked on Android's **main thread**. Callbacks are invoked AFTER the respective method returns. \n\n\n### Built-in listeners\nThe following listener interfaces are bundled with the library: \n\n- [ActivityAirCycle](aircycle-api/src/main/java/com/github/simonpercic/aircycle/ActivityAirCycle.java)\n- [ActivityBundleAirCycle](aircycle-api/src/main/java/com/github/simonpercic/aircycle/ActivityBundleAirCycle.java)\n- [ActivityPassAirCycle](aircycle-api/src/main/java/com/github/simonpercic/aircycle/ActivityPassAirCycle.java)\n\n### ActivityLifecycleCallbacks\nSince its method names are also supported by AirCycle, you can also use [Application.ActivityLifecycleCallbacks](https://developer.android.com/reference/android/app/Application.ActivityLifecycleCallbacks.html) as a bound listener.\n\n### Custom listeners\nAny class or interface that has at least one listener method can be bound as an AirCycle listener.\n\n[Custom listener](example/src/main/java/com/github/simonpercic/example/aircycle/activity/a7/CustomListener.java) from the example app:\n```java\npublic class CustomListener {\n\n    public void onCreate() {\n        \n    }\n\n    public void onCreate(CustomListenerActivity activity) {\n        \n    }\n\n    public void onCreate(Bundle bundle) {\n        \n    }\n\n    public void onSaveInstanceState(AppCompatActivity activity, Bundle bundle) {\n        \n    }\n\n    public void onActivitySaveInstanceState(Bundle bundle, Activity activity) {\n        \n    }\n}\n```\n\n#### Multiple methods\nAs seen above, multiple methods are supported for the same lifecycle callback (either overriden with different arguments or using an alternative supported name).\nThe order and naming of arguments is NOT important.\nNo arguments are necessary for any lifecycle method.\n\n\n## Multiple listeners\nA single Activity can have multiple fields bound to its lifecycle.\n\n[Multiple listeners Activity](example/src/main/java/com/github/simonpercic/example/aircycle/activity/a6/MultipleListenersActivity.java) from the example app:\n\n```java\npublic class MultipleListenersActivity extends AppCompatActivity {\n\n    @AirCycle ActivityAirCycleLogger airCycleLogger;\n    @AirCycle final ActivityBundleAirCycleLogger bundleAirCycleLogger = new ActivityBundleAirCycleLogger();\n    \n    // ...\n}\n```\n\n\n## Configuration\nCreate an `AirCycleConfig` using the builder:\n```java\nAirCycleConfig airCycleConfig = AirCycleConfig.builder()\n    // options ...\n    .build();\n```\n\n#### Apply when binding\nYou can pass an instance of `AirCycleConfig` to the generated \u0026lt;YourActivity\u0026gt;AirCycle `bind` method when binding and it will only apply to that instance of the Activity.\n```java\nMyActivityAirCycle.bind(this, airCycleConfig);\n```\n\n#### Apply as a default config\nAlternatively, you can set an `AirCycleConfig` as the app-wide default config and it will be applied to all the AirCycles that don't have another config applied when binding.\n```java\nAirCycleDefaultConfig.setConfig(airCycleConfig);\n```\n\n### Configuration options\n- `passIntentBundleOnCreate(true|false)` if true, it passes the Activity's starting Intent Extras Bundle only if its savedInstanceState is null in onCreate(), i.e. getIntent().getExtras() with null-checks. If false, it always passes the savedInstanceState. Defaults to `false`. \n\n- `ignoreLifecycleCallback(int)` ignore an Activity lifecycle callback. Pass an `ActivityLifecycleEvent` IntDef from [ActivityLifecycle](aircycle-api/src/main/java/com/github/simonpercic/aircycle/ActivityLifecycle.java)'s constants.\n\n\n## Ignore Activity lifecycle callbacks\nThere are 3 options to ignore lifecycle callbacks:\n\n- `@AirCycle` annotation option `ignore`:\n```java\n@AirCycle(ignore = {ActivityLifecycle.RESUME, ActivityLifecycle.PAUSE}) ActivityAirCycleLogger airCycleLogger;\n```\n\n- annotate a listener method with `@Ignore`:\n```java\npublic class CustomListener {\n\n    // ...\n\n    @Ignore\n    public void onStart() {\n    \n    }\n\n    // ...\n}\n```\n\n- `AirCycleConfig` configuration option: \n```java\nAirCycleConfig airCycleConfig = AirCycleConfig.builder()\n    // ...\n    .ignoreLifecycleCallback(ActivityLifecycle.RESUME)\n    .ignoreLifecycleCallback(ActivityLifecycle.PAUSE)\n    // ...\n    .build();\n```\n\n\n## How does it work?\nAirCycle generates one binding class per-Activity containing 1 or more `@AirCycle` annotated field(s). \nUpon calling `bind` on a generated class passing the Activity instance, [Application.ActivityLifecycleCallbacks](https://developer.android.com/reference/android/app/Application.ActivityLifecycleCallbacks.html) are registered on the Activity's app.\nThese are automatically unregistered for the Activity once onDestroy is called.\n\nThe listener callbacks are invoked only if the listener instance is not null and are dispatched only to their respective bound listener instances.\n\n\n## ProTip\nAnnotate your Dagger injected presenters to automatically bind them to the Activity lifecycle, i.e.\n```java\n@AirCycle @Inject MyPresenter presenter;\n```\n\n\n## Reflection-less\nAirCycle uses compile time annotation processing to generate Activity binding classes, NO reflection is used at runtime.\n\n\n## ProGuard\nSince all classes are generated in compile time and no reflection is used in runtime, you can safely use AirCycle with ProGuard.\n\n\n## Include in your project\n\n```groovy\nbuildscript {\n    dependencies {\n        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'\n    }\n}\n\napply plugin: 'com.neenbedankt.android-apt'\n\ndependencies {\n    compile 'com.github.simonpercic:aircycle:1.2.0'\n    apt 'com.github.simonpercic:aircycle-compiler:1.2.0'\n}\n```\n\nSince Android Gradle Plugin version 2.2.0\n```groovy\ndependencies {\n    compile 'com.github.simonpercic:aircycle:1.2.0'\n    annotationProcessor 'com.github.simonpercic:aircycle-compiler:1.2.0'\n}\n```\n\n\n## Inspiration and motivation\nInspired by [SoundCloud's](https://developers.soundcloud.com/blog/category/mobile) [LightCycle](https://github.com/soundcloud/lightcycle) library. Kudos to those guys.\n\nCompared to SoundCloud's library, AirCycle supports passing of Activity lifecycle callbacks without the need to extend from a specific base Activity.\nAdditionally, the listener classes are completely flexible, without the need to extend from any class or interface. \nThis enables more flexibility when developing and further promotes composition over inheritance.\n\nThe cost of this flexibility is only supporting Activity lifecycle callbacks included in [Application.ActivityLifecycleCallbacks](https://developer.android.com/reference/android/app/Application.ActivityLifecycleCallbacks.html) (since API level 14) and no support for Fragment lifecycle callbacks.\n\n\n## Change Log\nSee [CHANGELOG.md](CHANGELOG.md)\n\n\n## License\nOpen source, distributed under the MIT License. See [LICENSE](LICENSE) for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimonpercic%2Faircycle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimonpercic%2Faircycle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimonpercic%2Faircycle/lists"}