0
votes

I'm writing an application using libgdx and am having a weird issue.

When the game loads, it works well. The moment you exit the game, and load it again - the graphics are all scrambled (ie - the textures its loading are swapped with other textures, so I might have the texture for the ground replaced with the texture for the main character...).

Clearing the game from the history (and I'm assuming from the cache?) means the game loads perfectly on next time.

So is there a way to tell Android (from the configuration I'm assuming) to not cache the application when I 'close' it?

2

2 Answers

0
votes

Using these lines in your activity:-

this.finish();
Process.killProcess( Process.myPid() ); 

will kill your whole application (assuming its running in a single process) it will also free any associated memory.

This may help in game to load perfectly next time at application will be killed completely.

0
votes

You can use the following code to remove the catch for your application, Call it from onDestroy() of your activity from where you are going to exit from the application

public static void deleteCache(Context context) {
    try {
        File dir = context.getCacheDir();
        if (dir != null && dir.isDirectory()) {
            deleteDir(dir);
        }
    } catch (Exception e) {}
}

public static boolean deleteDir(File dir) {
    if (dir != null && dir.isDirectory()) {
        String[] children = dir.list();
        for (int i = 0; i < children.length; i++) {
            boolean success = deleteDir(new File(dir, children[i]));
            if (!success) {
                return false;
            }
        }
    }
    return dir.delete();
}