分类 Android 下的文章

LifeCycle源码解读

对于LifeCycle的简单使用可以看上一篇文章:LiveData+ViewModel+Repository搭建MVVM

这篇文章主要是为了阅读源码,尽量深入阅读,能力还是一般,见谅:

LifeCycle的作用

解决onCreate等生命周期方法,由于各种原因,后期越来越臃肿的问题。

关键类阐述

LifecycleRegistryOwner/LifecycleOwner

在Activity等组件生命周期发生变化的时候,发出相应的Event给LifecycleRegistry。

LifecycleRegistry

控制state的转换、接受分发Event事件。

LifecycleObserver

通过注解绑定Event和自定义的函数,实现对生命周期的监听并处理。

Event

@SuppressWarnings("WeakerAccess")
public enum Event {
    /**
     * Constant for onCreate event of the {@link LifecycleOwner}.
     */
    ON_CREATE,
    /**
     * Constant for onStart event of the {@link LifecycleOwner}.
     */
    ON_START,
    /**
     * Constant for onResume event of the {@link LifecycleOwner}.
     */
    ON_RESUME,
    /**
     * Constant for onPause event of the {@link LifecycleOwner}.
     */
    ON_PAUSE,
    /**
     * Constant for onStop event of the {@link LifecycleOwner}.
     */
    ON_STOP,
    /**
     * Constant for onDestroy event of the {@link LifecycleOwner}.
     */
    ON_DESTROY,
    /**
     * An {@link Event Event} constant that can be used to match all events.
     */
    ON_ANY
}

- 阅读剩余部分 -

LiveData+ViewModel+Repository搭建MVVM

什么是LiveData

LiveData is an observable data holder class. Unlike a regular observable, LiveData is lifecycle-aware, meaning it respects the lifecycle of other app components, such as activities, fragments, or services. This awareness ensures LiveData only updates app component observers that are in an active lifecycle state.
Source:https://developer.android.com/topic/libraries/architecture/livedata.html

什么是ViewModel

The ViewModel class is designed to store and manage UI-related data in a lifecycle conscious way. The ViewModel class allows data to survive configuration changes such as screen rotations.
Source:https://developer.android.com/topic/libraries/architecture/viewmodel

ViewModel的生命周期

ViewModel的生命周期

- 阅读剩余部分 -

Hotfix流程

文档

Hotfix完整步骤

检出线上分支,打线上包

创建线上Hotfix分支,修复bug,验证通过后打Hotfix包

使用SophixPatchTool工具生成补丁,教程请看:移动热修复 > 快速集成 > 生成补丁

进入Hotfix管理后台,如果没有创建过应用,需先进入应用管理页面创建应用,然后进入移动热修复页面上传补丁(需要注意:如果没有添加过版本号需要先添加)

上传成功后,点击补丁一行右边的操作按钮详情,进入补丁管理详情页,然后根据扫码验证补丁的操作指示去验证补丁是否可以在本机生效(PS:不仅需要验证之前打的线上包,还需要在本机下应用市场的包去验证),教程请看:移动热修复 > 快速集成 > 调试补丁,如果手机上没有安装过hotfixdebug,请先安装apk。

验证通过后,可以全量发布补丁,然后再下一个应用商店的包去验证就好了。