其他分享
首页 > 其他分享> > Android P中不推荐使用碎片

Android P中不推荐使用碎片

作者:互联网

我看着documentation并发现了这一点

This class was deprecated in API level P.

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

解决方法:

在支持库27.1.0中重写

Ian’s medium post(2018年2月28日)给我们一个解释.他是Google的Android Framework开发人员.

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,新的实施基于生命周期.

Important Changes
The underlying implementation of 07002 has been rewritten to use 07003.

架构组件

Support Library 26.1.0,Fragment和FragmentActivity采用了生命周期.

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.

相比之下,Android P中的FragmentActivity尚未实现LifecycleOwner接口.

the Google+ post(ThanosFisherman’s answer中提到),伊恩发表评论:

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.

标签:android-9-0-pie,android,android-fragments
来源: https://codeday.me/bug/20190928/1828003.html