Question

During my game there is a spot where I detachChildren before reattaching them so I do as follow:

activity.getEngine().runOnUpdateThread(new Runnable(){
            public void run() {
                detachChildren();
            }
        });

But when they reattach the game crashes as if the entities were never detached. This is since I added admob. I suspect the thread admob runs on doesn't give the time to to update thread to do its job.

I tried setting the update thread priority to maximum, as such:

this.getEngine().getEngineOptions().setUpdateThreadPriority(android.os.Process.THREAD_PRIORITY_URGENT_DISPLAY);

But it didn't help. Therefore my question is, how can I make sure the updateThread's runnable finishes its job before running the rest of my code? Or, alternatively how can I make its priority higher than adMob's?

Thanks.

Was it helpful?

Solution

I decided to do as such... altough I find it's inelegant, it works.

public void loseAndRestart(){
        if(runnableDone){
            if(livesLost>2){
                saveHigh();
                youLooseStartAgainPrompt(0);
            } else if (youLooseScreen){
                youLooseScreen = false;
                scoreTally.reset();
                lifeTally.firstInit();
            } else {
                scoreTally.reattach();
                lifeTally.init();
            }
            if(!youLooseScreen){
                diddly.init();
                craneEngine.purgeAndInit();
                torch.init();
                pipeNDrops.init();
                lifeLost = false;
            }
            runnableDone = false;
        } else {
            activity.getEngine().runOnUpdateThread(new Runnable(){
                public void run() {
                    detachChildren();
                    runnableDone = true;
                    loseAndRestart();
                }
            });
        }
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top