最佳答案
支持库 27.1.0 中的重写
Ian's medium post (2018 年 2 月 28 日)给我们一个解释。他是 Google 的 Android 框架开发人员。
Loaders in Support Library 27.1.0
For Support Library 27.1.0, I rewrote the internals of LoaderManager, the class powering the Loaders API and I wanted to explain the reasoning behind the changes and what to expect going forward.
Loaders and Fragments, a history
From the beginning, Loaders and Fragments were pretty tightly tied together at the hip. This meant that a lot of the code in FragmentActivity and Fragment were there to support Loaders, despite the fact that there are indeed fairly independent. …What’s changed in 27.1.0
With 27.1.0, the technical debt of Loaders has been greatly reduced: ……
Note: Obviously, these changes only apply to Support Library Loaders. If you are using Android framework Loaders, please switch to the Support Library Loaders as soon as possible. There are no bug fixes or improvements planned for the framework Loader APIs.
Fragment
和 FragmentActivity
中的代码似乎已被重构,以使 Loaders 成为可选依赖项。
根据the release note ,新的实现基于Lifecycle
。
Important Changes
The underlying implementation of Loaders has been rewritten to use Lifecycle.
架构组件
在 Support Library 26.1.0 、Fragment
和 FragmentActivity
采用了 Lifecycle
。
This is a special release to integrate the Support Library with Lifecycles from Architecture Components. If you are not using the Lifecycles library, you don’t need to update from 26.0.2. For more information, see the Architecture Components release notes.
Important changes
- Fragment and FragmentActivity (the base class for AppCompatActivity) now implement the LifecycleOwner interface from Architecture Components.
相比之下,Fragment和 Activity Android P 中没有实现接口(interface)LifecycleOwner
。
在 the Google+ post (在 ThanosFisherman’s answer 中提到),Ian 发表评论:
you can't change framework code after it has shipped - it is literally frozen in time. That means no new features and more importantly no bug fixes. That's not a good developer experience, particularly when we do have a fully supported, up to date, backward compatible version in the Support Library.
我认为这就是 Android P 不采用 Lifecycle
的原因。因此 Fragment
在 Android P 中已被弃用。
关于android - Android P 中不推荐使用的 fragment ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49446411/