2
\$\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\$

2 Answers 2

4
\$\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\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .