Glide.with(Activity) 也是让 Activity 创建出一个 Fragment ,在 Fragment 的各个生命周期方法内插入回调函数后,执行代码来实现的

Posted liyanyan665

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Glide.with(Activity) 也是让 Activity 创建出一个 Fragment ,在 Fragment 的各个生命周期方法内插入回调函数后,执行代码来实现的相关的知识,希望对你有一定的参考价值。

SupportActivity.java(support库)
------------------------------
@Override
@SuppressWarnings("RestrictedApi")
protected void onCreate(@Nullable Bundle savedInstanceState)
super.onCreate(savedInstanceState);
ReportFragment.injectIfNeededIn(this);



ComponentActivity.java(androidx库)
------------------------------
@Override
@SuppressWarnings("RestrictedApi")
protected void onCreate(@Nullable Bundle savedInstanceState)
super.onCreate(savedInstanceState);
ReportFragment.injectIfNeededIn(this);



ReportFragment.java
------------------------------
@Override
public void onActivityCreated(Bundle savedInstanceState)
super.onActivityCreated(savedInstanceState);
dispatchCreate(mProcessListener);
dispatch(Lifecycle.Event.ON_CREATE);


@Override
public void onStart()
super.onStart();
dispatchStart(mProcessListener);
dispatch(Lifecycle.Event.ON_START);


@Override
public void onResume()
super.onResume();
dispatchResume(mProcessListener);
dispatch(Lifecycle.Event.ON_RESUME);


@Override
public void onPause()
super.onPause();
dispatch(Lifecycle.Event.ON_PAUSE);


@Override
public void onStop()
super.onStop();
dispatch(Lifecycle.Event.ON_STOP);


@Override
public void onDestroy()
super.onDestroy();
dispatch(Lifecycle.Event.ON_DESTROY);
// just want to be sure that we won‘t leak reference to an activity
mProcessListener = null;


private void dispatch(Lifecycle.Event event)
Activity activity = getActivity();
if (activity instanceof LifecycleRegistryOwner)
((LifecycleRegistryOwner) activity).getLifecycle().handleLifecycleEvent(event);
return;


if (activity instanceof LifecycleOwner)
Lifecycle lifecycle = ((LifecycleOwner) activity).getLifecycle(http://www.amjmh.com/v/BIBRGZ_558768/);
if (lifecycle instanceof LifecycleRegistry)
((LifecycleRegistry) lifecycle).handleLifecycleEvent(event);

————————————————

以上是关于Glide.with(Activity) 也是让 Activity 创建出一个 Fragment ,在 Fragment 的各个生命周期方法内插入回调函数后,执行代码来实现的的主要内容,如果未能解决你的问题,请参考以下文章

初始化:Glide.java

初始化:Glide.java

Glide错误java.lang.IllegalArgumentException: You cannot start a load for a destroyed activity

Glide高级详解—缓存与解码复用

glide 设置 ivRecordReply.background 为圆形网络图片

Glide 4.12 框架源码中的生命周期设计