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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With