gpt4 book ai didi

android - Android P 中不推荐使用的 fragment

转载 作者:IT王子 更新时间:2023-10-29 00:04:11 24 4
gpt4 key购买 nike

我在看 documentation并找到了这个

This class was deprecated in API level P.

为什么在 android P 中不推荐使用 Fragment?

最佳答案

支持库 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.

FragmentFragmentActivity 中的代码似乎已被重构,以使 Loaders 成为可选依赖项。

根据the release note ,新的实现基于Lifecycle

Important Changes
The underlying implementation of Loaders has been rewritten to use Lifecycle.

架构组件

Support Library 26.1.0FragmentFragmentActivity 采用了 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.

相比之下,FragmentActivity 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com