views:

50

answers:

1

I have a main game thread but when the target score is achieved I have an activity that is launched called StageCleared which basically displays the stats to the user of their performance and then they can press a continue button to carry on with the game. This should switch focus back to the running thread that should continue execution, and thus display the game activity (with parameters i update after StageCleared has exectued).

It was suggested I use a package visible object that calls wait() on itself in the main game thread, and then notify() on itself from StageCleared in order to continue execution. My first problem is I can't seem to declare a package visible object that can be seen by all the classes in my package? Secondly, is this the best way to achieve what I'm intending to do or is there a better way?

Many thanks

A: 

To enable package visibile, leave the modifier blank:

static boolean mVarname = true;

mVarname is visible inside the package.

I work with a run flag to enable if the loop should do something or just "idle". I, too, dont know if this is a good way to do it :)

WarrenFaith
Thanks, I thought that was how but it still doesn't like it. At the moment what I'm trying is an Object that I pass a reference to in a method called on a variable of type StageCleared. I will see if that can solve it. It's an obscure way of using the same object but you have to love pointers in cases like this.
Greenhouse Gases
Using synchronized with the thread as an argument is the answer I think from my noodling around, it has solved the problem of an IllegalMonitorStateException. Perhaps that will come in handy for you too if ever you need it!
Greenhouse Gases