{"id":16482127,"url":"https://github.com/bod/android-activitylifecyclecallbacks-compat","last_synced_at":"2025-03-21T07:30:38.914Z","repository":{"id":6502578,"uuid":"7743107","full_name":"BoD/android-activitylifecyclecallbacks-compat","owner":"BoD","description":"Android ActivityLifecycleCallbacks Compatibility Library","archived":false,"fork":false,"pushed_at":"2013-10-26T08:50:17.000Z","size":643,"stargazers_count":80,"open_issues_count":2,"forks_count":17,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-17T22:37:18.097Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BoD.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-01-22T00:22:13.000Z","updated_at":"2024-04-12T05:19:12.000Z","dependencies_parsed_at":"2022-08-26T04:01:32.461Z","dependency_job_id":null,"html_url":"https://github.com/BoD/android-activitylifecyclecallbacks-compat","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BoD%2Fandroid-activitylifecyclecallbacks-compat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BoD%2Fandroid-activitylifecyclecallbacks-compat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BoD%2Fandroid-activitylifecyclecallbacks-compat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BoD%2Fandroid-activitylifecyclecallbacks-compat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BoD","download_url":"https://codeload.github.com/BoD/android-activitylifecyclecallbacks-compat/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244757204,"owners_count":20505348,"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-10-11T13:09:43.464Z","updated_at":"2025-03-21T07:30:38.604Z","avatar_url":"https://github.com/BoD.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"Android ActivityLifecycleCallbacks Compatibility Library\n========================================================\n\nA 'compatibility' version of the ActivityLifecycleCallbacks APIs (http://developer.android.com/reference/android/app/Application.ActivityLifecycleCallbacks.html)\nthat were introduced in Android 4 (API Level 14).\n\nThis library works on Android 1+.\n\nGoal\n----\n\nSometimes it is useful to execute a piece of code on certain life cycle methods of all your activities.\n\nFor instance the Google Analytics library requires you to call a specific method in `onStart` and `onStop` of all your activities.\n\nOne way to do this is to have a base activity that does the job in `onStart` and `onStop` and then have all your activities extend it.\nBut this is not ideal - if you use several libraries like this, your activity hierarchy could start to get deep (and \nhard to read / maintain).\n\nThis is why the ActivityLifecycleCallbacks APIs were introduced in Android 4.\n\nBasically you call `registerActivityLifecycleCallbacks` on your `Application`, passing an `ActivityLifecycleCallbacks`\nand the system will call the methods following the life cycle of all the activities.\n\nThis library allows you to use these APIs in versions of Android lower than 4.\n\nWhat's the catch?\n-----------------\n\nUnfortunately there is no way to intercept the activity life cycle methods except by having your activities extend some base \nclass from this library.\n\n*\"So what's the point?\"*, you may ask.\n\n1. This library provides base 'instrumented' versions of the most commonly used `Activity` flavors: `Activity`, `FragmentActivity`, `ListActivity`, etc.\n2. The API is basically the same as the one introduced in Android 4, so when you decide to drop support for older versions of the platform, you won't have to rewrite code: you can just remove this library and replace a few lines of code.\n\nHow to use\n----------\n\nThis is an Android library project, you have to add it as a dependency to your project (please\nsee http://developer.android.com/guide/developing/projects/projects-eclipse.html#ReferencingLibraryProject to\nknow how to do that.)\n\nOnce you have done that, you simply need to call `ApplicationHelper.registerActivityLifecycleCallbacks(Application, ActivityLifecycleCallbacksCompat)`\ninstead of calling `Application.registerActivityLifecycleCallbacks(ActivityLifecycleCallbacks)` (which exists only since Android 4).\n\nThen you need to have all your activities extend one of the base activities in the `org.jraf.android.util.activitylifecyclecallbackscompat.app` package.\nFor instance instead of:\n```java\n    public class MainActivity extends Activity {\n```\n    \nUse:\n```java\n    public class MainActivity extends LifecycleDispatchActivity {\n```\n\nAn example application is available in the `example-project` folder.\n\nUsing ActionBarSherlock or a similar library\n--------------------------------------------\n\nIf you use a library that already requires your activities to extend a base class (e.g. ActionBarSherlock),\nsimply create your own base activity using `LifecycleDispatchActivity.java` as a starting point.\nHere is an example for the ActionBarSherlock library:\n```java\n    public class MyBaseActivity extends SherlockFragmentActivity {\n        @Override\n        protected void onCreate(Bundle savedInstanceState) {\n            super.onCreate(savedInstanceState);\n            if (ApplicationHelper.PRE_ICS) MainLifecycleDispatcher.get().onActivityCreated(this, savedInstanceState);\n        }\n    \n        @Override\n        protected void onStart() {\n            super.onStart();\n            if (ApplicationHelper.PRE_ICS) MainLifecycleDispatcher.get().onActivityStarted(this);\n        }\n    \n        @Override\n        protected void onResume() {\n            super.onResume();\n            if (ApplicationHelper.PRE_ICS) MainLifecycleDispatcher.get().onActivityResumed(this);\n        }\n    \n        @Override\n        protected void onPause() {\n            super.onPause();\n            if (ApplicationHelper.PRE_ICS) MainLifecycleDispatcher.get().onActivityPaused(this);\n        }\n    \n        @Override\n        protected void onStop() {\n            super.onStop();\n            if (ApplicationHelper.PRE_ICS) MainLifecycleDispatcher.get().onActivityStopped(this);\n        }\n    \n        @Override\n        protected void onSaveInstanceState(Bundle outState) {\n            super.onSaveInstanceState(outState);\n            if (ApplicationHelper.PRE_ICS) MainLifecycleDispatcher.get().onActivitySaveInstanceState(this, outState);\n        }\n    \n        @Override\n        protected void onDestroy() {\n            super.onDestroy();\n            if (ApplicationHelper.PRE_ICS) MainLifecycleDispatcher.get().onActivityDestroyed(this);\n        }\n    }\n```\n\nLicence\n-------\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\nhttp://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%2Fbod%2Fandroid-activitylifecyclecallbacks-compat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbod%2Fandroid-activitylifecyclecallbacks-compat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbod%2Fandroid-activitylifecyclecallbacks-compat/lists"}