Android P中不推荐使用的片段 [英] Fragments deprecated in Android P

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

问题描述

我正在查看文档,并找到了

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

This class was deprecated in API level P.

为什么Android P中不推荐使用片段?

Why are fragments deprecated in android P?

推荐答案

支持库27.1.0中的重写

伊恩的中级帖子( 2018年2月28日)为我们提供了解释.他是Google的Android Framework开发人员.

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.

加载程序和片段,历史
从一开始,Loader和Fragments在臀部就紧密地绑在一起.这意味着即使存在确实相当独立的事实,FragmentActivity和Fragment中的许多代码仍在这里以支持Loader. …

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,大大降低了装载机的技术债务:

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

...

注意:显然,这些更改仅适用于支持库加载程序.如果您使用的是Android框架加载程序,请尽快切换到支持库加载程序.没有计划对框架Loader 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.

重要更改
加载程序的基础实现已重写为使用

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

建筑组件

支持库26.1.0 中,FragmentFragmentActivity已采用Lifecycle.

Architecture Components

In Support Library 26.1.0, Fragment and FragmentActivity has adopted Lifecycle.

这是一个特殊版本,用于将支持库与体系结构组件的生命周期集成在一起.如果您不使用生命周期库,则不需要从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接口.

相反,片段

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

Google+帖子中(在ThanosFisherman的答案),伊恩发表了评论:

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的原因.因此在Android P中不推荐使用Fragment.

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天全站免登陆