扩展 LifecycleActivity,Activity,ActionbarActivity & 的区别AppCompactActivity? [英] Difference between extending LifecycleActivity,Activity,ActionbarActivity & AppCompactActivity?

查看:24
本文介绍了扩展 LifecycleActivity,Activity,ActionbarActivity & 的区别AppCompactActivity?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Android 中,扩展 Lifecycler Activity、Activity、ActionBarActivity & 的主要区别是什么?AppCompactActivity?这些类在使用方面有何不同?

解决方案

编辑:更多详情:

ActionBarActivity支持库的一部分.支持库用于在旧平台上提供新功能.例如,ActionBar 是在 API 11 中引入的,默认情况下是 Activity 的一部分(实际取决于主题).相比之下,旧平台上没有 ActionBar.所以支持库添加了一个Activity(ActionBarActivity)的子类,提供ActionBar的功能和ui

edit2:2015 年 4 月更新 - 看起来 ActionBarActivity 在支持库的 revision 22.1.0 中已被弃用.AppCompatActivity 应该是改为使用.

edit3: 2017 年 8 月更新 - LifecycleActivity 是一个 LifecycleOwner 但是:><块引用>

由于架构组件处于 alpha 阶段,Fragment 和AppCompatActivity 类无法实现它(因为我们无法添加从稳定组件到不稳定 API 的依赖).直到Lifecycle 是稳定的,LifecycleActivity 和 LifecycleFragment 类为方便而提供.在 Lifecycles 项目完成之后发布,支持库片段和活动将实现LifecycleOwner 接口;LifecycleActivity 和 LifecycleFragment 将届时将被弃用."

(从架构组件指南中复制)

In Android what is the main difference between extending Lifecycler Activity, Activity,ActionBarActivity & AppCompactActivity? How do these classes differ from each other in terms of usage?

解决方案

  • extending ActionBarActivity gives you the ActionBars functionality on every API level >= 7
  • by extending Activity you can avoid adding additional projects/libraries to your project but you'll lack the ActionBar on api levels below 11

edit: More details:

ActionBarActivity is part of the Support Library. Support libraries are used to deliver newer features on older platforms. For example the ActionBar was introduced in API 11 and is part of the Activity by default (depending on the theme actually). In contrast there is no ActionBar on the older platforms. So the support library adds a child class of Activity (ActionBarActivity) that provides the ActionBar's functionality and ui

edit2: Update April 2015 - it looks like the ActionBarActivityis deprecated in revision 22.1.0 of the Support Library. AppCompatActivity should be used instead.

edit3: Update Aug 2017 - LifecycleActivity is a LifecycleOwner but:

"Since the Architecture Components are in alpha stage, Fragment and AppCompatActivity classes cannot implement it (because we cannot add a dependency from a stable component to an unstable API). Until Lifecycle is stable, LifecycleActivity and LifecycleFragment classes are provided for convenience. After the Lifecycles project is released, support library fragments and activities will implement the LifecycleOwner interface; LifecycleActivity and LifecycleFragment will be deprecated at that time."

(copied from the Architecture Components guideline)

这篇关于扩展 LifecycleActivity,Activity,ActionbarActivity &amp; 的区别AppCompactActivity?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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