Lifecycle Component
2018-05-19 14:11:27 2 举报
Android Lifecycle的UML图,附带一些源码截图和注释 自己边学习边画的,大概理了一下Lifecycle感知生命周期的原理 红色*号的是关键方法 蓝色背景是Lifecycle相关的类 黄色背景是Lifecycle相关接口 有错误的地方欢迎指出,一起学习
作者其他创作
大纲/内容
android.support.v4.app.Fragment
performCreate():voidperformCreateView():ViewperformActivityCreated():voidperformStart():voidperformResume():voidperformPause():voidperformStop():voidperformDestory():void
mLifecycleRegistry : LifecycleRegistry
1、SupportActivity在onCreate的时候,给自己加了个ReportFragment用来向LifeCycleRegister发送生命周期状态
Lifecycling
getCallback():GenericLifecycleObserver
*
ReprotFragment通过SupportActivity的mLifecycleRegistry来发送生命周期状态变化
ReflectiveGenericLifecycleObserver
mInfo : CallbackInfo //LifecycleObserver的信息,主要是检查有没有用OnLifecycleEvent注解的方法mWrapped:Object //这个就是你自定义的LifecycleObserver
android.Fragment
内部静态类
实现
LifecycleRegistry
backwardPass( LifecycleOwner ):void ( 调用ObserverWithState.dispatchEvent() )forwardPass( LifecycleOwner ):voidhandleLifecycleEvent( Lifecycle.Event ):void(最终由上面两个函数实现)addObserver( LifecycleObserver ):void
3、LifecycleRegistry.handleLifecycleEvent调用ObserverWithState.dispatchEvent
abstract Lifecycle
Event(enum)
ON_CREATEON_STARTON_RESUMEON_PAUSEON_STOPON_DESTROYON_ANY
ReportFragment
+ dispatchCreate(ActivityInitializationListener):void+ dispatchStart(ActivityInitializationListener):void+ dispatchResume(ActivityInitializationListener):void+ dispatch(LifeCycle.Event event)
4、ObserverWithState.dispatchEvent调用ReflectiveGenericLifecycleObserver. onStateChanged
内部类
GenericLifecycleObserver
LifecycleObserver
Lifecycle是怎么让观察者知道Activity/Fragment的生命周期状态的?
ObserverWithState
mLifecycleObserver: GenericLifecycleObserver
继承
2、ReprotFragment在每个生命周期方法中调用dispatch方法,通过SupportActivity的lifecycle发送生命周期状态
LifeCycleOnwer
- Lifecycle getLifecycle();
SupportActivity
收藏
0 条评论
下一页
为你推荐
查看更多