Questions about AppState(s)

In order to be able to change from one state to another and enable me to use the initialize every time I switch to the new state I do this…

[java]

stateTwo.setEnabled(false);

stateManager.detach(stateTwo);

stateTwo.cleanup();

stateManager.attach(stateOne);

stateOne.setEnabled(true);

[/java]

and this…

[java]

stateOne.setEnabled(false);

stateManager.detach(stateOne);

stateOne.cleanup();

stateManager.attach(stateTwo);

stateTwo.setEnabled(true);

[/java]

is that necessary? (it works but do I need to keep attaching and detaching things to the AppStateManager?) I suppose my real question is, is this the best (or at least a good) way to switch between AppStates?



Thanks

Depends on your AppState, can you afford keeping the state initialized when its not used? Then setEnabled() should suffice, if you set up lots of data and e.g. models, you should probably detach it, yeah. At any instance, you define what is happening on setEnabled() and attach() etc.

normen said:
Depends on your AppState, can you afford keeping the state initialized when its not used?

Probably, but I think that I will keep on attaching and detaching them for now, I can always change it at a later date quite easily. My concern was whether it would cause significant problems doing it this way but actually it seems that there is more merit in doing it this way that the other, I am planning on having different game types in my game and each will load lots of assets (some same some not) and I didn't even consider this...
normen said:
if you set up lots of data and e.g. models, you should probably detach it

which means that all assets that aren't referenced any more can be garbage collected, right?

So I think I'll leave as is any way :)

Thanks
Neilos said:
which means that all assets that aren't referenced any more can be garbage collected, right?

Again what actually happens is defined by your class. Personally I would probably clean up the AppState when its detached, e.g. clear all lists, put all variables to null etc.