@NonNull privatestatic RequestManagerRetriever getRetriever(@Nullable Context context) { // Context could be null for other reasons (ie the user passes in null), but in practice it will // only occur due to errors with the Fragment lifecycle. Preconditions.checkNotNull( context, "You cannot start a load on a not yet attached View or a Fragment where getActivity() " + "returns null (which usually occurs when getActivity() is called before the Fragment " + "is attached or after the Fragment is destroyed)."); return Glide.get(context).getRequestManagerRetriever(); }
@NonNull public RequestManager get(@NonNull Context context) { if (context == null) { thrownewIllegalArgumentException("You cannot start a load on a null Context"); } elseif (Util.isOnMainThread() && !(context instanceof Application)) { if (context instanceof FragmentActivity) { return get((FragmentActivity) context); } elseif (context instanceof Activity) { return get((Activity) context); } elseif (context instanceof ContextWrapper // Only unwrap a ContextWrapper if the baseContext has a non-null application context. // Context#createPackageContext may return a Context without an Application instance, // in which case a ContextWrapper may be used to attach one. && ((ContextWrapper) context).getBaseContext().getApplicationContext() != null) { return get(((ContextWrapper) context).getBaseContext()); } }
return getApplicationManager(context); }
前面会判断 Context ,然后再走不同的 get ,这些我们都跳过,来看最后的 getApplicationManager 。
@NonNull private RequestManager getApplicationManager(@NonNull Context context) { // Either an application context or we're on a background thread. if (applicationManager == null) { synchronized (this) { if (applicationManager == null) { // Normally pause/resume is taken care of by the fragment we add to the fragment or // activity. However, in this case since the manager attached to the application will not // receive lifecycle events, we must force the manager to start resumed using // ApplicationLifecycle.
// TODO(b/27524013): Factor out this Glide.get() call. Glideglide= Glide.get(context.getApplicationContext()); applicationManager = factory.build( glide, newApplicationLifecycle(), newEmptyRequestManagerTreeNode(), context.getApplicationContext()); } } }