Stack Overflow Asked by Mikhail Kiselyov on December 27, 2020
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);
}
}
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
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP