AnswerBun.com

LibGDX Android Gdx.app.exit() doesnt work, how to close app in another way?

I’m trying to close template app for android (5 sec after render() method is started).
Application is closing, but activity is alive in backgroung and I can back to app if I want.
When I’m using this.dispose() without timer, right in the end of render() method it works fine – no activity to resume Application, but when gdx draw anything this issue occures.
I’ve tried put in timer: Gdx.app.exit() / this.dispose() / System.exit(-1) and nothing helps if render() method already working some time.

Here is the code:

public class MyGdxGame extends ApplicationAdapter {
SpriteBatch batch;
Texture img;
MyGdxGame instance;
boolean isReadyToClose = false;

@Override
public void create () {
    instance = this;
    batch = new SpriteBatch();
    img = new Texture("badlogic.jpg");
}

@Override
public void render () {

    Gdx.gl.glClearColor(1, 0, 0, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    batch.begin();
    batch.draw(img, 0, 0);
    batch.end();

    if (!isReadyToClose) {

        isReadyToClose = true;

        new Timer().scheduleTask(new Timer.Task() {
            @Override
            public void run() {

                //instance.dispose();
                Gdx.app.exit();

            }
        }, 5);

    }

}

@Override
public void dispose () {
    batch.dispose();
    img.dispose();

    System.exit(-1);
}
}

Stack Overflow Asked by Mikhail Kiselyov on December 27, 2020

1 Answers

One Answer

You aren't supposed to exit apps on mobile platforms, Gdx.app.exit is intended to be used on desktop. Exit on Android works by the user pressing the back key and your application not catching it.

Correct answer by MrStahlfelge on December 27, 2020

Add your own answers!

Related Questions

How to center a flex container but left-align flex items

7  Asked on December 22, 2021 by etienne-nol

     

about IComponentConnector2

0  Asked on December 22, 2021 by yushang

   

WooCommerce order again and custom item data for price calculation

1  Asked on December 22, 2021 by elizabeth-parodi-roman

         

ruby how to stop the execution after rescue

1  Asked on December 22, 2021 by jill448

     

LSTM predicting constant value throughout

0  Asked on December 22, 2021 by harrys

         

Use main scrollbar to scroll all elements in the page

1  Asked on December 22, 2021 by marsilinou-zaky

         

How to read file from createReadStream in Node.js?

3  Asked on December 22, 2021 by ton1

   

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved.