v0.9.1: more android lifecycle adjustments, fixes bugs and another leak?

This commit is contained in:
Evan Debenham 2020-12-07 14:18:31 -05:00
parent e821eabaae
commit 8428d7cd89
2 changed files with 9 additions and 18 deletions

View File

@ -23,12 +23,10 @@ package com.shatteredpixel.shatteredpixeldungeon.android;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.opengl.GLSurfaceView;
import android.os.Build;
import android.os.Bundle;
import com.badlogic.gdx.Files;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.backends.android.AndroidApplication;
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
import com.shatteredpixel.shatteredpixeldungeon.SPDSettings;
@ -43,7 +41,6 @@ import com.watabou.utils.FileUtils;
public class AndroidGame extends AndroidApplication {
public static AndroidApplication instance;
protected static GLSurfaceView view;
private static AndroidPlatformSupport support;
@ -112,8 +109,6 @@ public class AndroidGame extends AndroidApplication {
initialize(new ShatteredPixelDungeon(support), config);
view = (GLSurfaceView)graphics.getView();
}
@Override
@ -134,16 +129,8 @@ public class AndroidGame extends AndroidApplication {
//LibGDX itself doesn't clear these in every case, so we do it ourselves to be sure
graphics.clearManagedCaches();
audio.dispose();
Gdx.app = null;
Gdx.input = null;
Gdx.audio = null;
Gdx.files = null;
Gdx.graphics = null;
Gdx.net = null;
if (instance == this) {
instance = null;
view = null;
}
super.onDestroy();
}

View File

@ -26,11 +26,13 @@ import android.content.Context;
import android.content.pm.ActivityInfo;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.opengl.GLSurfaceView;
import android.os.Build;
import android.view.View;
import android.view.WindowManager;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.backends.android.AndroidGraphics;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.PixmapPacker;
@ -54,11 +56,13 @@ public class AndroidPlatformSupport extends PlatformSupport {
ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT );
}
if (AndroidGame.view.getMeasuredWidth() == 0 || AndroidGame.view.getMeasuredHeight() == 0)
GLSurfaceView view = (GLSurfaceView) ((AndroidGraphics)Gdx.graphics).getView();
if (view.getMeasuredWidth() == 0 || view.getMeasuredHeight() == 0)
return;
Game.dispWidth = AndroidGame.view.getMeasuredWidth();
Game.dispHeight = AndroidGame.view.getMeasuredHeight();
Game.dispWidth = view.getMeasuredWidth();
Game.dispHeight = view.getMeasuredHeight();
boolean fullscreen = Build.VERSION.SDK_INT < Build.VERSION_CODES.N
|| !AndroidGame.instance.isInMultiWindowMode();
@ -99,7 +103,7 @@ public class AndroidPlatformSupport extends PlatformSupport {
AndroidGame.instance.runOnUiThread(new Runnable() {
@Override
public void run() {
AndroidGame.view.getHolder().setFixedSize(finalW, finalH);
view.getHolder().setFixedSize(finalW, finalH);
}
});
@ -108,7 +112,7 @@ public class AndroidPlatformSupport extends PlatformSupport {
AndroidGame.instance.runOnUiThread(new Runnable() {
@Override
public void run() {
AndroidGame.view.getHolder().setSizeFromLayout();
view.getHolder().setSizeFromLayout();
}
});
}