Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is one Activity = one Context?

I am confused to differ between context and activity. what is context anyway? does context belongs to one activity ? will the context change if the activity is changed?

I have a game which has multiple activity. each activity for each part, splashscreen, menu, gamescreen , etc. The problem is I have one singleton SoundManager which use soundpool as it's sound player. I want to load every sound in splashscreen. But after I think it once again, how about the context?

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

if I load the sounds in SplashScreen Activity, how could I play the sound in GameScreen Activity? different context isn't it?

like image 529
Fugogugo Avatar asked Mar 28 '11 03:03

Fugogugo


1 Answers

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

On Android, a Context is used for many operations but mostly to load and access resources. This is why all the widgets receive a Context parameter in their constructor. In a regular Android application, you usually have two kinds of Context, Activity and Application.

And from the Android docs:

It allows access to application-specific resources and classes, as well as up-calls for application-level operations such as launching activities, broadcasting and receiving intents, etc.

Typically each Activity will have it's own Context and the Application itself will have a Context.

like image 62
brendan Avatar answered Oct 04 '22 13:10

brendan