当一个 Activity 实例在配置更改期间被销毁时,与其关联的加载器是否也被销毁?

When an Activity instance is destroyed during a configuration change, are the Loaders associated with it also destroyed?

从这份关于加载程序的开发者指南中,

They automatically reconnect to the last loader's cursor when being recreated after a configuration change. Thus, they don't need to re-query their data.

我假设 "last loader",它们的意思是当 Activity 在配置更改期间被销毁时被销毁的加载程序。然后说 "last loader's cursor",它们表示与最后一个加载程序关联的游标。这告诉我们 当 Activity 由于配置更改而被销毁时,它的加载器也会被销毁,但游标(或加载器加载的任何其他形式的数据)不会被销毁。对吗?

其实要内化这个有点难。我的直觉告诉我们,当加载器被销毁时,与其关联的所有东西,包括与其关联的游标也应该被销毁。

Loader 实例在配置更改期间保持活动状态。旧的Activity的LoaderCallbacks断开了,新的重新连接了。

看看 LoaderManager.java LoaderInforetain()finishRetain() 方法。可以看到mCallbacks字段为空,而mLoader字段没有。

这些字段的初始化发生在 LoaderInfo.start() 中,您可以看到 mCallbacks.onCreateLoader() 只有 mLoader 为 null 时调用。