Android P 中弃用的片段 [英] Fragments deprecated in Android P

查看:22
本文介绍了Android P 中弃用的片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在查看 文档 并找到了这个

I was looking at the documentation and found this

该类在 API 级别 P 中已弃用.

This class was deprecated in API level P.

为什么片段在 android P 中被弃用?

Why are fragments deprecated in android P?

推荐答案

Support Library 27.1.0 中的重写

伊恩的中型帖子(2018 年 2 月 28 日)给了我们一个解释.他是 Google 的 Android 框架开发人员.

The rewrite in Support Library 27.1.0

Ian's medium post (Feb 28, 2018) gives us an explanation about it. He is Android Framework Developer at Google.

支持库 27.1.0 中的加载器

对于支持库 27.1.0,我重写了 LoaderManager 的内部结构,该类为 Loaders API 提供支持,我想解释更改背后的原因以及对未来的期望.

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 和 Fragments 就紧紧地绑在了一起.这意味着 FragmentActivity 和 Fragment 中的很多代码都支持加载器,尽管它们确实相当独立.……

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. …

27.1.0 中的变化
在 27.1.0 中,Loaders 的技术债务已经大大减少:......

What’s changed in 27.1.0
With 27.1.0, the technical debt of Loaders has been greatly reduced: …

注意:显然,这些更改仅适用于支持库加载器.如果您正在使用 Android 框架加载器,请尽快切换到支持库加载器.没有针对框架加载程序 API 的错误修复或改进计划.

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 成为可选依赖项.

It seems like the code in Fragment and FragmentActivity has been refactored in order to make Loaders an optional dependency.

根据发行说明,新的实现基于Lifecycle.

重要变化
Loaders 的底层实现已被重写为使用 生命周期.

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

架构组件

支持库 26.1.0FragmentFragmentActivity 已采用 Lifecycle.

这是一个特殊版本,用于将支持库与架构组件的生命周期集成.如果您没有使用 Lifecycles 库,则不需要从 26.0.2 更新.有关更多信息,请参阅架构组件发行说明.

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.

重要变化

  • Fragment 和 FragmentActivity(AppCompatActivity 的基类)现在实现了来自架构组件的 LifecycleOwner 接口.

相比之下,FragmentActivity在Android P中没有实现LifecycleOwner接口.

By contrast, Fragment and Activity in Android P have not implemented the interface LifecycleOwner.

Google+ 帖子(在ThanosFisherman 的回答),Ian 发表了评论:

In the Google+ post (mentioned in ThanosFisherman’s answer), Ian made a comment:

框架代码在交付后就无法更改——它确实被时间冻结了.这意味着没有新功能,更重要的是没有错误修复.这不是一种良好的开发者体验,尤其是当我们的支持库中有一个完全受支持的、最新的、向后兼容的版本时.

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 中被弃用.

I think that’s the reason why Android P doesn't adopt Lifecycle. Consequently Fragment is deprecated in Android P.

这篇关于Android P 中弃用的片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆