Hi all, So I'm struggling a bit with what is probably a fairly basic concept.. Activity Lifecycle.
I have read a bunch of thread on the topic, and I feel I understand well both the functionality, and rationale behind the lifecycle model implemented for Activities, but it raises a bit of a problem for me. My app (game) has a couple of distinct Activities for various sections: 1. The TitleActivity is a very small Activity that just launches a GLSurfaceView and renders a startup logo. I use this to detect the OpenGL capabilities of the device (eg so I know if it's using a software renderer) 2. The LaunchActivity is the main menu screen where the user can access options etc and start a game 3. The GameActivity will either launches a GLSurfaceView or a standard View depending on hardware capabilties. The issue I am having is that I want to pre-load some "slow-to-load" resources, specifically audio, in the Title Activity so when the Launch Activity renders I can play some background music. I have the concept of a "media library" which I use throughout the game. Because of memory limitations in the SoundPool, I have limited this to only absolute real-time sounds and all others are played using mulitple instances of MediaPlayer. Hence my media library has a bunch of pre-loaded MediaPlayer instances which I access regularly during game play.. so it makes sense to have a centralized access point for all audio. All fine, however the problem is that when I launch one activity from another.. for example the TitleActivity starts the LaunchActivity (via a call to startActivity(Intent...)), the former goes through the onDestroy stage of its lifecycle. Now logically I had assumed that if I allocate a bunch of resources in the onCreate of an Activity, I should clean them up in the onDestroy, however in the case of my "media library" if I load up the audio files in the onCreate of my TitleActivity they will be torn down when the LaunchActivity is started because the TitleActivity will have its onDestroy() method called. So.. the question is... Is it possible to have data bound to the lifecycle of the entire application? I'm trying to avoid two scenarios: 1. Loading up all resources and tearing them down again every time the Activity is created/destroyed 2. Splitting up the resources based on Activity. In the latter case (2) I could minimize the load time by limiting the resources loaded based on the Activity, but this means I need to know ahead of time which resources that activity will need.. which is a pain. In the former case (1) my load time for each level of the game will be blown out because I have to completely reload the world when it hasn't actually changed. As you've probably guessed, my media library is just sitting in static scope.. basically a poor-man's singleton. Ideally I would like to be able to setup and tear down these resources when the entire application is created or destroyed. Is this even possible? And if not does anyone have a pattern that makes sense for this? (besides having one monster Activity where everything else is a View) I also have some background threads that suffer the same problem. That is, do I have to start and stop them with every Activity start/ stop? Thanks! -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

