libgdx 上的 launchMode="singleTask" 不工作,游戏在 phone 锁定时重新启动

launchMode="singleTask" on libgdx isn't working and game restarts on phone lock

我在 libgdx 上有一个项目,我正在使用启动画面。问题是,每次我在主菜单上阻止我的 phone 并再次解锁时,游戏会再次显示启动画面,我不希望它 "restart" 游戏而是留在原处


编辑:为避免发布所有不必要的代码,我将解释我是如何制作的:

简单 class 将游戏调用 setScreen 扩展到启动画面,然后在 3 秒后启动画面调用主菜单,我希望启动画面不会再次出现,除非游戏被销毁并再次打开

代码:

public MainMenuScreen(final TowerConquest gam) {
    game = gam;
}

@Override
public void show() {
    stage = new Stage(new FillViewport(800, 480));
    Gdx.input.setInputProcessor(stage);
    //((OrthographicCamera)stage.getCamera()).setToOrtho(false, 800, 480);
    atlas = new TextureAtlas("skins/userInterface.pack");
    skin = new Skin(atlas);
    table = new Table(skin);
    table.setBounds(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    white = new BitmapFont(Gdx.files.internal("font/white.fnt"), false);
    black = new BitmapFont(Gdx.files.internal("font/black.fnt"), false);

    TextButtonStyle textButtonStyle = new TextButtonStyle();
    textButtonStyle.up = skin.getDrawable("normalbutton");
    textButtonStyle.down = skin.getDrawable("pressedbutton");
    textButtonStyle.disabled = skin.getDrawable("dissabledbutton");
    textButtonStyle.pressedOffsetX = 1;
    textButtonStyle.pressedOffsetY = -1;
    textButtonStyle.font = black;
    buttonPlay = new TextButton("PLAY", textButtonStyle);
    buttonPlay.pad(20);
    buttonPlay.addListener(new ClickListener(){
        @Override
        public void clicked(InputEvent event, float x, float y) {
            game.setScreen(new testGame(game));
            //Gdx.input.vibrate(150);
            dispose();
        }
    });

    buttonExit = new TextButton("EXIT", textButtonStyle);
    buttonExit.pad(20);
    buttonExit.addListener(new ClickListener(){
        @Override
        public void clicked(InputEvent event, float x, float y) {
            dispose();
            Gdx.app.exit();
        }
    });

    LabelStyle headingStyle = new LabelStyle(white, Color.WHITE);

    heading = new Label("Tower Conquest", headingStyle);
    table.add(heading);
    table.getCell(heading).padBottom(50);
    table.row();
    table.add(buttonPlay);
    table.getCell(buttonPlay).spaceBottom(15);
    table.row();
    table.add(buttonExit);
    table.debug();
    table.setOrigin(table.getWidth()/2, table.getHeight()/2);
    table.setFillParent(true);
    stage.addActor(table);      
}

@Override
public void render(float delta) {
    Gdx.gl.glClearColor(0, 0, 0.2f, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    stage.act(delta);
    stage.draw();
}

@Override
public void resize(int width, int height) {
    my resizes...
}

@Override
public void pause() {
}

@Override
public void resume() {
}

@Override
public void hide() {
}

@Override
public void dispose() {
    all disposes..
}

我找到了答案,将其添加到清单文件中

android:configChanges="keyboard|keyboardHidden|screenSize|orientation">

这是因为当屏幕锁定时,它会将方向更改为纵向,因此它会重新启动应用程序,启用该选项后,它不会重新启动应用程序