startActivity(this,OtherActivity.class)如何使用Context对象来启动活动?

时间:2015-10-14 06:01:30

标签: android android-activity android-context

我开始阅读有关上下文的内容而且我有点困惑。

我找到了以下定义。

The Context class is an “Interface to global information about an application environment.” 
  

这里我不了解android应用程序环境是什么?

我们可以使用 1。 getAssets()2。getResources()3。getPackageManager()4。getString()5。getSharedPrefsFile()方法,我们也可以启动一个活动,使用Context广播一个Intent。

我认为,上述方法(加粗)可以为应用提供应用的全局数据,

  

这些资源是否称为App全球数据?

     

因此,对于启动活动,Android使用了哪些全局信息   系统

     

View如何使用Context(从Context获取哪些信息)?

我对Context类的概念以及所有这些事情的相关性感到非常困惑。

请提供任何帮助。

1 个答案:

答案 0 :(得分:0)

请查看上下文详细信息。我认为这些事情可以帮助你理解背景的概念。

    View.getContext():
 Returns the context the view is currently running in. Usually the currently active Activity.

    Activity.getApplicationContext():
 Returns the context for the entire application (the process all the Activities are running inside of). Use this instead of the current Activity context if you need a context tied to the lifecycle of the entire application, not just the current Activity.

    ContextWrapper.getBaseContext():
 If you need access to a Context from within another context, you use a ContextWrapper. The Context referred to from inside that ContextWrapper is accessed via getBaseContext().