为什么在活动课生命周期方法定义了受保护的访问说明 [英] Why are lifecycle methods in activity class defined with protected access specifier

查看:129
本文介绍了为什么在活动课生命周期方法定义了受保护的访问说明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的理解有关访问说明符是如下 ::

what i understand about Access-specifiers is as below::

  • 但是,为什么我们应该需要让所有的生命周期方法作为 保护
  • 在我注意到这一点,当我重写生命周期方法
  • 我知道压倒一切的活动类的方法中的方法 活动类定义保护
  • 但是,他们为什么定义为保护
  • But why should we need to make all the life-cycle methods as protected
  • I notice this when i override the lifecycle methods
  • I know over-riding the methods of Activity class as methods in Activity class are defined protected
  • But why are they defined as protected

推荐答案

  • 在他们 保护 的框架包中封装< A HREF =htt​​p://developer.android.com/reference/android/app/package-summary.html相对=nofollow> android.app <​​/A>和子类。
  • 他们是由 android.app调用。 ActivityManager (同一个包)而已。根据不同的方法实现,事情会变得一团糟,如果一个人可以任意调用这些方法,从任何地方。

所以,这是由设计,并且设计有利于避免某些观念上的误区。 如果你真的必须有一个公开的方法,只是实现一个与外界和相应的生命周期方法中使用它。
然而,尽管不建议在这种情况下,人们可以覆盖保护的方法公开的方法。

So, this is by design and that design helps to avoid certain conceptual errors. If you really must have a public method, just implement one and use it from outside and within the corresponding lifecycle method.
However, though not recommended in this case, one could override protected methods with public methods.

这篇关于为什么在活动课生命周期方法定义了受保护的访问说明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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