Do not dispose host on android

This commit is contained in:
Bartłomiej Dach
2024-04-26 10:04:05 +02:00
parent b3314484f9
commit dad23c0c65

View File

@@ -11,6 +11,7 @@ using Java.Lang;
using ManagedBass;
using Org.Libsdl.App;
using osu.Framework.Extensions.ObjectExtensions;
using osu.Framework.Platform;
using Debug = System.Diagnostics.Debug;
namespace osu.Framework.Android
@@ -33,6 +34,8 @@ namespace osu.Framework.Android
internal static AndroidGameSurface Surface => (AndroidGameSurface)MSurface!;
private GameHost? host;
protected abstract Game CreateGame();
protected override string[] GetLibraries() => new string[] { "SDL3" };
@@ -46,21 +49,19 @@ namespace osu.Framework.Android
// hints are here because they don't apply well in another location such as SDL3Window
using (AndroidGameHost host = new AndroidGameHost(this))
host = new AndroidGameHost(this);
host.AllowScreenSuspension.Result.BindValueChanged(allow =>
{
host.AllowScreenSuspension.Result.BindValueChanged(allow =>
RunOnUiThread(() =>
{
RunOnUiThread(() =>
{
if (!allow.NewValue)
Window?.AddFlags(WindowManagerFlags.KeepScreenOn);
else
Window?.ClearFlags(WindowManagerFlags.KeepScreenOn);
});
}, true);
if (!allow.NewValue)
Window?.AddFlags(WindowManagerFlags.KeepScreenOn);
else
Window?.ClearFlags(WindowManagerFlags.KeepScreenOn);
});
}, true);
host.Run(CreateGame());
}
host.Run(CreateGame());
if (!IsFinishing)
Finish();
@@ -84,6 +85,12 @@ namespace osu.Framework.Android
}
}
public override void OnTrimMemory(TrimMemory level)
{
base.OnTrimMemory(level);
host?.Collect();
}
protected override void OnStop()
{
base.OnStop();