Search code examples
javaandroidinheritanceandroid-activity

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. 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.

Funny thing is the Activity class also inherits from ContetxtWrapper

Why isn't the Context class referred to as the base class of all android components?


Solution

  • The Application class in Android is the base class within an Android app that contains all other components such as activities and services. 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.

    This class is primarily used for initialization of global state before the first Activity is displayed. Note that custom Application objects should be used carefully and are often not needed at all

    Reference

     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.

    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]

    So Object Class should be base class in Android.

    But,

    As Documentation say's

    Class Object is the root of the class hierarchy. Every class has Object as a superclass. All objects, including arrays, implement the methods of this class.