JessYanCoding / Lifecyclemodel
Licence: apache-2.0
📬 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
Stars: ✭ 233
Programming Languages
java
68154 projects - #9 most used programming language
Projects that are alternatives of or similar to Lifecyclemodel
Mvparms
⚔️ A common architecture for Android applications developing based on MVP, integrates many open source projects, to make your developing quicker and easier (一个整合了大量主流开源项目高度可配置化的 Android MVP 快速集成框架).
Stars: ✭ 10,146 (+4254.51%)
Mutual labels: android-architecture, mvparms
Mvpart
🎨 A new Android MVP architecture (此框架旨在解决传统 MVP 类和接口太多, 并且 Presenter 和 View 通过接口通信过于繁琐, 重用 Presenter 代价太大等问题).
Stars: ✭ 776 (+233.05%)
Mutual labels: android-architecture, mvparms
Mvvmarms
Android MVVM Architecture Components based on MVPArms and Android Architecture Components.
Stars: ✭ 425 (+82.4%)
Mutual labels: android-architecture, mvparms
Armscomponent
📦 A complete android componentization solution, powered by MVPArms (MVPArms 官方快速组件化方案).
Stars: ✭ 1,664 (+614.16%)
Mutual labels: android-architecture, mvparms
Eiffel
Redux-inspired Android architecture library leveraging Architecture Components and Kotlin Coroutines
Stars: ✭ 203 (-12.88%)
Mutual labels: android-architecture
Coolweather
Weather App that uses Android best practices. Android Jetpack, clean architecture. Written in Kotlin
Stars: ✭ 154 (-33.91%)
Mutual labels: android-architecture
Android Developer Roadmap
Android Developer Roadmap - A complete roadmap to learn Android App Development
Stars: ✭ 2,170 (+831.33%)
Mutual labels: android-architecture
Bubbble
Sample app showcases the MVP pattern and Robert Martin's Clean Architecture approach.
Stars: ✭ 226 (-3%)
Mutual labels: android-architecture
Progressmanager
⏳ Listen the progress of downloading and uploading in Okhttp, compatible Retrofit and Glide (一行代码即可监听 App 中所有网络链接的上传以及下载进度, 包括 Glide 的图片加载进度).
Stars: ✭ 2,463 (+957.08%)
Mutual labels: mvparms
Knot
Unidirectional reactive state container for Android & Kotlin
Stars: ✭ 198 (-15.02%)
Mutual labels: android-architecture
Droid Feed
Aggregated Android news, articles, podcasts and conferences about Android Development
Stars: ✭ 174 (-25.32%)
Mutual labels: android-architecture
Clean Architecture Android
Sample to practice Clean Architecture in android applications.
Stars: ✭ 207 (-11.16%)
Mutual labels: android-architecture
Notzz App
📝 A Simple Note-Taking App built to demonstrate the use of Modern Android development tools - (Kotlin, Coroutines, State Flow, Hilt-Dependency Injection, Jetpack DataStore, Architecture Components, MVVM, Room, Material Design Components).
Stars: ✭ 158 (-32.19%)
Mutual labels: android-architecture
Web Dev Tools Android
Sample Android Application - MVVM, Clean Architecture, Modularization, Repository Pattern
Stars: ✭ 215 (-7.73%)
Mutual labels: android-architecture
Retrofiturlmanager
🔮 Let Retrofit support multiple baseUrl and can be change the baseUrl at runtime (以最简洁的 Api 让 Retrofit 同时支持多个 BaseUrl 以及动态改变 BaseUrl).
Stars: ✭ 1,961 (+741.63%)
Mutual labels: mvparms
Component
🔥🔥🔥A powerful componentized framework.一个强大、100% 兼容、支持 AndroidX、支持 Kotlin并且灵活的组件化框架
Stars: ✭ 2,434 (+944.64%)
Mutual labels: android-architecture
Cw Androidarch
Source Code for the Book "Android's Architecture Components"
Stars: ✭ 213 (-8.58%)
Mutual labels: android-architecture
Jimu
一种简单有效的android组件化方案,支持组件的代码资源隔离、单独调试、集成调试、组件交互、UI跳转、生命周期等完整功能。
Stars: ✭ 2,355 (+910.73%)
Mutual labels: android-architecture
Android Spotify Mvp
Android Sample to explain Model View Presenter in android applications.
Stars: ✭ 184 (-21.03%)
Mutual labels: android-architecture
LifecycleModel
ViewModel
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 onIntroduction
LifecycleModel 基于 Google 在 2017 年 I/O 大会上发布的 Android 架构组件中的 ViewModel, 可以帮助 Activity 和 Fragment 储存和管理一些与 UI 相关以及他们必需的数据, 避免数据在屏幕旋转或配置更改时发生的数据丢失, 还可以帮助开发者轻易实现 Fragment 与 Fragment 之间, Activity 与 Fragment 之间的通讯以及共享数据, 因为我看到 Google 让 MVVM 框架中的 ViewModel 具有了这些功能, 所以我也想让 MVP 框架中的 Presenter, 乃至其他更多的模块都具有这些功能, 所以 LifecycleModel 诞生了
Lifecycle
Download
implementation 'me.jessyan:lifecyclemodel:1.0.1'
Usage
Step 1
public class UserLifecycleModel implements LifecycleModel {
private int id;
public UserLifecycleModel(int id) {
this.id = id;
}
void doAction() {
}
@Override
public void onCleared() {
//release resources
}
}
Step 2
//Put data
LifecycleModelProviders.of(activity/fragment).put(UserLifecycleModel.class.getName(), new UserLifecycleModel(1));
//Get data
LifecycleModelProviders.of(activity/fragment).get(UserLifecycleModel.class.getName());
//Remove data
LifecycleModelProviders.of(activity/fragment).remove(UserLifecycleModel.class.getName());
Communication of the Activity / Fragment
public class UserLifecycleModel implements LifecycleModel {
private Subject<String, String> mSubject = PublishSubject.create();
public void doAction(String s) {
mSubject.onNext(s);
}
public void addAction(Action1<String> action) {
mSubject.subscribe(action);
}
}
public class AFragment extends Fragment {
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
UserLifecycleModel lifecycleModel = LifecycleModelProviders.of(getActivity()).get(UserLifecycleModel.class.getName());
lifecycleModel.addAction(new Action1<String>() {
@Override
public void call(String s) {
// Update the UI.
}
});
}
}
public class BFragment extends Fragment {
@Override
public void onStart() {
super.onStart();
UserLifecycleModel lifecycleModel = LifecycleModelProviders.of(getActivity()).get(UserLifecycleModel.class.getName());
lifecycleModel.doAction("JessYan");
}
}
About Me
- Email: [email protected]
- Home: http://jessyan.me
- 掘金: https://gold.xitu.io/user/57a9dbd9165abd0061714613
- 简书: http://www.jianshu.com/u/1d0c0bc634db
License
Copyright 2017, jessyan
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].