[英]What is the actual base class of all Android classes?
Before now, I have read articles and tutorials that say the base class of all Android components is the Application
.在此之前,我读过一些文章和教程,这些文章和教程说所有 Android 组件的基类都是
Application
。 But when I take a deeper dive into the inheritance, I find out that the Application
class inherits from ContextWrapper
which equally inherits the Context
class too.但是当我深入研究继承时,我发现
Application
类继承自ContextWrapper
,它同样继承了Context
类。
Funny thing is the Activity
class also inherits from ContetxtWrapper
有趣的是
Activity
类也继承自ContetxtWrapper
Why isn't the Context
class referred to as the base class of all android components?为什么
Context
类不称为所有 android 组件的基类?
The Application class in Android is the base class within an Android app that contains all other components such as activities and services.
Android 中的 Application 类是 Android 应用程序中的基类,它包含所有其他组件,例如活动和服务。 The Application class, or any subclass of the Application class, is instantiated before any other class when the process for your application/package is created.
在为您的应用程序/包创建进程时,Application 类或 Application 类的任何子类在任何其他类之前被实例化。
This class is primarily used for initialization of global state before the first Activity is displayed.
此类主要用于在显示第一个 Activity 之前初始化全局状态。 Note that custom Application objects should be used carefully and are often not needed at all
请注意,应谨慎使用自定义 Application 对象,并且通常根本不需要
Why isn't the Context class referred to as the base class of all
android components?
The Application class in Android is the base class within an Android app that contains all other components such as activities and services.
Android 中的 Application 类是 Android 应用程序中的基类,它包含所有其他组件,例如活动和服务。
I think above line's will remove your confusion as base class does not only mean's what it implement/extend's it's more about what it contain's.我认为上面这行会消除您的困惑,因为基类不仅意味着它实现/扩展的内容,还意味着它包含的内容。
By your logic if you go deeper into hierarchy at-last all the Classes like Application/Activity/ContextWrapper will be extending [Object Class][2]
根据您的逻辑,如果您最终深入层次结构,所有类(如 Application/Activity/ContextWrapper)都将扩展
[Object Class][2]
So Object Class should be base class in Android.所以对象类应该是Android中的基类。
But,但,
As Documentation say's正如文档所说的
Class Object is the root of the class hierarchy.
类对象是类层次结构的根。 Every class has Object as a superclass.
每个类都有一个 Object 作为超类。 All objects, including arrays, implement the methods of this class.
所有对象,包括数组,都实现了这个类的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.