1
\$\begingroup\$

when I press back button on android, it exits the game although I ask it to go to other screen instead. It goes to the other screen for one or two seconds then it exits.:

if((Gdx.input.isKeyPressed(Input.Keys.BACK)))
    game.setScreen(new GameOverScreen(game,4));
\$\endgroup\$
3
\$\begingroup\$

More code would be helpful, but you likely need to put this in your show method.

public void show() {
    Gdx.input.setInputProcessor(yourInputProcessor);
    // This should keep it from exiting.
    Gdx.input.setCatchKey(Input.Keys.BACK, true);
    ...
}
\$\endgroup\$
1
\$\begingroup\$

in your update method you should add the below code.

    if (Gdx.input.isKeyPressed(Keys.BACK)) {
        game.setScreen(new MenuScreen(game));
    }

// and in your game Screen classes show method Add this code

        Gdx.input.setCatchBackKey(true);
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.