I'm working on a multiplayer game using libgdx. I want to handle sending some log out info to the server before the connection is closed. From what I've read Libgdx's ApplicationAdapter class' dispose() method is not always called when the app is closed, for instance if its closed while its paused. I've read other people suggest to others, who just want to dispose assets, that they should put it into the pause method, but in my situation I don't want it called when it's just paused, for instance if I just push the home screen or move to another app. I only want it to be called when I'm actually closing the app, such as if I were to go to the android application overview screen by pressing the bottom right button, to see all the apps running, and swiping up on my game to remove it and terminate it, or if the game crashes. Where can I put it so that it is called everytime the app terminates, but only if it terminates, not if its just paused or in the background. To reproduce I provided a generic libgdx project, all I added was the Log.i command.
package com.mycompany.mygame;
import com.badlogic.gdx.*;
import com.badlogic.gdx.graphics.*;
import com.badlogic.gdx.graphics.g2d.*;
import android.util.*;
public class MyGdxGame implements ApplicationListener
{
Texture texture;
SpriteBatch batch;
@Override
public void create()
{
texture = new Texture(Gdx.files.internal("android.jpg"));
batch = new SpriteBatch();
}
@Override
public void render()
{
Gdx.gl.glClearColor(1, 1, 1, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
batch.draw(texture, Gdx.graphics.getWidth() / 4, 0,
Gdx.graphics.getWidth() / 2, Gdx.graphics.getWidth() / 2);
batch.end();
}
@Override
public void dispose()
{
Log.i("test", "dispose ran");
}
@Override
public void resize(int width, int height)
{
}
@Override
public void pause()
{
}
@Override
public void resume()
{
}
}