上周面试阿里的客户端开发岗位, 终面的时候,部门老大问过这样一个问题:Acitivty的直接父类是什么,它有没有直接或者间接地继承View?
先看看google官方文档中关于Acitivity的描述,
An activity is a single, focused thing that the user can do. Almost all activities interact with the user, so the Activity class takes care of creating a window for you in which you can place your UI with setContentView(View).
再看关于View的描述,
This class represents the basic building block for user interface components. A View occupies a rectangular area on the screen and is responsible for drawing and event handling. View is the base class for widgets, which are used to create interactive UI components (buttons, text fields, etc.)
简言之,Activity是一个单独的、聚焦的和用户直接进行交互的组件,这个组件是View的容器,View控件只有放置在这个容器里面才有意义。在MVC的设计模式里面,Activity是Control,负责与用户交互的业务逻辑,而View控件则是将这些业务逻辑显示在屏幕上。