Welcome 微信登录
编程资源 图片资源库 蚂蚁家优选 PDF转换器

首页 / 操作系统 / Linux / 从源码中Activity 的定义来理解 Activity

首先我们来看下源码中源于Activity的定义:
  1. public class Activity extends ContextThemeWrapper  
  2.         implements LayoutInflater.Factory2,  
  3.         Window.Callback, KeyEvent.Callback,  
  4.         OnCreateContextMenuListener, ComponentCallbacks2 {  
  5.     ...  
  6. }  
下面我们来详细分析每一部分的具体意义:extends ContextThemeWrapper表示Activity本质上是一个ContextThemeWrapper,而ContextThemeWrapper具体是什么呢?看ContextThemeWrapper在源码中的定义:
  1. public class ContextThemeWrapper extends ContextWrapper {  
  2.     ...  
  3. }  
可见ContextThemeWrapper是一个ContextWrapper,继续往下看: 
  1. public class ContextWrapper extends Context {  
  2.       Context mBase;  
  3.     ...  
  4. }  
ContextWrapper本质上是一个Context,context 的定义如下:  
  1. public abstract class Context {  
  2.     ...  
  3. }  
整体结构如下图所示