代码改变世界

Android widget: Activity context vs. Application context

2013-12-13 09:53  xiao蜗牛  阅读(377)  评论(0编辑  收藏  举报

1 Something we know:

  Activity & Application are all indirect subclasses of Context.

java.lang.Object
↳ android.content.Context
↳ android.content.ContextWrapper
↳ android.view.ContextThemeWrapper
↳ android.app.Activity

--------------

java.lang.Object
↳ android.content.Context
↳ android.content.ContextWrapper
↳ android.app.Application

2 From the above hierarchy view we find out that the difference between Activity and Application 

is the class 'ContextThemeWrapper' -- it's the parent of Activity, but not Application.

 

3 What does ContextThemeWrapper for?

  A ContextWrapper that allows you to modify the theme from what is in the wrapped context.

  So, we get the biggest difference between Activity and Application:

  We can modify the theme by Acitity, but can't by Application .

 

4 How does Activity modify the theme?

  To be continued...