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

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

问题描述

在Android中,扩展Lifecycler Activity,Activity,ActionBarActivity& AppCompactActivity?这些类在用法上有何不同?

解决方案

修改:更多详细信息:

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

edit2 :更新于2015年4月-支持库的revision 22.1.0中似乎已弃用ActionBarActivity. 应该代替使用 AppCompatActivity . >

edit3:更新于2017年8月- LifecycleActivity LifecycleOwner ,但是:

由于架构组件处于alpha阶段,因此Fragment和 AppCompatActivity类无法实现它(因为我们无法添加 从稳定的组件到不稳定的API的依赖性).直到 生命周期稳定,LifecycleActivity和LifecycleFragment类 为方便起见.在生命周期项目之后 发布后,支持库片段和活动将实现 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&之间的区别AppCompactActivity?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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