{"id":17978768,"url":"https://github.com/jessyancoding/lifecyclemodel","last_synced_at":"2025-03-25T17:31:39.965Z","repository":{"id":122734884,"uuid":"113399109","full_name":"JessYanCoding/LifecycleModel","owner":"JessYanCoding","description":"📬 The LifecycleModel class is designed to store and manage UI-related data in a lifecycle conscious way, the LifecycleModel class allows data to survive configuration changes such as screen rotations,  it also handles the communication of the Activity / Fragment with the rest of the application, base on https://developer.android.google.cn/topic/libraries/architecture/viewmodel.html","archived":false,"fork":false,"pushed_at":"2018-11-14T07:42:41.000Z","size":202,"stargazers_count":228,"open_issues_count":0,"forks_count":27,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-20T07:04:52.891Z","etag":null,"topics":["android","android-architecture","android-library","arms","mvparms"],"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/JessYanCoding.png","metadata":{"files":{"readme":"README.md","changelog":null,"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}},"created_at":"2017-12-07T03:39:36.000Z","updated_at":"2024-12-11T12:51:58.000Z","dependencies_parsed_at":null,"dependency_job_id":"7c0d0133-ebf6-4abc-80aa-f343fdc71420","html_url":"https://github.com/JessYanCoding/LifecycleModel","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JessYanCoding%2FLifecycleModel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JessYanCoding%2FLifecycleModel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JessYanCoding%2FLifecycleModel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JessYanCoding%2FLifecycleModel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JessYanCoding","download_url":"https://codeload.github.com/JessYanCoding/LifecycleModel/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245510728,"owners_count":20627246,"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","android-library","arms","mvparms"],"created_at":"2024-10-29T17:35:04.059Z","updated_at":"2025-03-25T17:31:39.661Z","avatar_url":"https://github.com/JessYanCoding.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LifecycleModel\n[ ![Jcenter](https://img.shields.io/badge/Jcenter-v1.0.1-brightgreen.svg?style=flat-square) ](https://bintray.com/jessyancoding/maven/lifecyclemodel/1.0.1/link)\n[ ![Build Status](https://travis-ci.org/JessYanCoding/LifecycleModel.svg?branch=master) ](https://travis-ci.org/JessYanCoding/LifecycleModel)\n[ ![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-LifecycleModel-brightgreen.svg?style=flat-square) ](https://android-arsenal.com/details/1/6545)\n[ ![API](https://img.shields.io/badge/API-14%2B-blue.svg?style=flat-square) ](https://developer.android.com/about/versions/android-4.0.html)\n[ ![License](http://img.shields.io/badge/License-Apache%202.0-blue.svg?style=flat-square) ](http://www.apache.org/licenses/LICENSE-2.0)\n[ ![Author](https://img.shields.io/badge/Author-JessYan-orange.svg?style=flat-square) ](https://www.jianshu.com/u/1d0c0bc634db)\n[ ![QQ-Group](https://img.shields.io/badge/QQ%E7%BE%A4-455850365%20%7C%20301733278-orange.svg?style=flat-square) ](https://shang.qq.com/wpa/qunwpa?idkey=7e59e59145e6c7c68932ace10f52790636451f01d1ecadb6a652b1df234df753)\n\n## The LifecycleModel class is designed to store and manage UI-related data in a lifecycle conscious way, the LifecycleModel class allows data to survive configuration changes such as screen rotations,  it also handles the communication of the Activity / Fragment with the rest of the application, base on [ViewModel](https://developer.android.google.cn/topic/libraries/architecture/viewmodel.html)\n\n## Introduction\n**LifecycleModel** 基于 Google 在 2017 年 I/O 大会上发布的 Android 架构组件中的 [**ViewModel**](https://developer.android.google.cn/topic/libraries/architecture/viewmodel.html), 可以帮助 **Activity** 和 **Fragment** 储存和管理一些与 UI 相关以及他们必需的数据, 避免数据在屏幕旋转或配置更改时发生的数据丢失, 还可以帮助开发者轻易实现 **Fragment** 与 **Fragment** 之间, **Activity** 与 **Fragment** 之间的通讯以及共享数据, 因为我看到 Google 让 **MVVM** 框架中的 **ViewModel** 具有了这些功能, 所以我也想让 **MVP** 框架中的 **Presenter**, 乃至其他更多的模块都具有这些功能, 所以 **LifecycleModel** 诞生了 \n\n\u003e [**框架的分析和思路**](https://juejin.im/post/5a31f6b951882503eb4b4b21)\n\n## Lifecycle\n![lifecycle](https://raw.githubusercontent.com/JessYanCoding/LifecycleModel/master/art/Lifecyclemodel-lifecycle.jpg)\n\n## Download\n``` gradle\n implementation 'me.jessyan:lifecyclemodel:1.0.1'\n```\n\n## Usage\n### Step 1\n```java\n public class UserLifecycleModel implements LifecycleModel {\n         private int id;\n \n         public UserLifecycleModel(int id) {\n             this.id = id;\n         }\n         \n         void doAction() {\n         \n         }\n \n         @Override\n         public void onCleared() {\n             //release resources\n         }\n     }\n```\n\n### Step 2\n```java\n //Put data\n LifecycleModelProviders.of(activity/fragment).put(UserLifecycleModel.class.getName(), new UserLifecycleModel(1));  \n\n //Get data\n LifecycleModelProviders.of(activity/fragment).get(UserLifecycleModel.class.getName());  \n \n //Remove data\n LifecycleModelProviders.of(activity/fragment).remove(UserLifecycleModel.class.getName());\n```\n\n### Communication of the Activity / Fragment\n```java\n public class UserLifecycleModel implements LifecycleModel {\n     private Subject\u003cString, String\u003e mSubject = PublishSubject.create();\n\n     public void doAction(String s) {\n         mSubject.onNext(s);\n     }\n\n     public void addAction(Action1\u003cString\u003e action) {\n         mSubject.subscribe(action);\n     }\n }\n \n public class AFragment extends Fragment {\n     @Override\n     public void onCreate(@Nullable Bundle savedInstanceState) {\n         super.onCreate(savedInstanceState);\n         UserLifecycleModel lifecycleModel = LifecycleModelProviders.of(getActivity()).get(UserLifecycleModel.class.getName());\n         lifecycleModel.addAction(new Action1\u003cString\u003e() {\n             @Override\n             public void call(String s) {\n                 // Update the UI.\n             }\n         });\n     }\n }\n \n public class BFragment extends Fragment {\n     @Override\n     public void onStart() {\n         super.onStart();\n         UserLifecycleModel lifecycleModel = LifecycleModelProviders.of(getActivity()).get(UserLifecycleModel.class.getName());\n         lifecycleModel.doAction(\"JessYan\");\n     }\n }\n```\n\n\n## About Me\n* **Email**: \u003cjess.yan.effort@gmail.com\u003e\n* **Home**: \u003chttp://jessyan.me\u003e\n* **掘金**: \u003chttps://gold.xitu.io/user/57a9dbd9165abd0061714613\u003e\n* **简书**: \u003chttp://www.jianshu.com/u/1d0c0bc634db\u003e\n\n## License\n```\n Copyright 2017, jessyan\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.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjessyancoding%2Flifecyclemodel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjessyancoding%2Flifecyclemodel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjessyancoding%2Flifecyclemodel/lists"}