一个Activity是一个Context吗?

Fug*_*ugo 7 android android-activity

我对上下文和活动之间的区别感到困惑.什么是背景呢?上下文属于一个活动吗?如果活动发生变化,上下文会改变吗?

我有一个有多种活动的游戏.每个部分的每个活动,启动画面,菜单,游戏屏幕等.问题是我有一个单独的SoundManager使用soundpool作为它的声音播放器.我想在启动画面中加载每个声音.但在我再次思考之后,背景如何呢?

   public void loadSound(Context context, int resId, String name) {
        int id = sounds.load(context, resId, priority)
    }
Run Code Online (Sandbox Code Playgroud)

如果我在SplashScreen Activity中加载声音,我怎么能在GameScreen Activity中播放声音?不同的背景不是吗?

bre*_*dan 8

Per:http://android-developers.blogspot.com/2009/01/avoiding-memory-leaks.html

在Android上,Context用于许多操作,但主要用于加载和访问资源.这就是为什么所有小部件在其构造函数中都接收Context参数的原因.在常规Android应用程序中,通常有两种Context,Activity和Application.

并从Android文档:

它允许访问特定于应用程序的资源和类,以及对应用程序级操作的上调,例如启动活动,广播和接收意图等.

通常,每个Activity都有自己的Context,Application本身也有Context.