Android: Detect when native code should flush unsaved data

This commit is contained in:
JosJuice
2025-04-26 10:33:01 +02:00
committed by Jordan Woyak
parent 2a771937cf
commit 0ba32f7add
4 changed files with 27 additions and 0 deletions

View File

@@ -56,10 +56,21 @@ class ActivityTracker : ActivityLifecycleCallbacks {
override fun onActivitySaveInstanceState(activity: Activity, bundle: Bundle) {}
override fun onActivityPostSaveInstanceState(activity: Activity, bundle: Bundle) {
if (DirectoryInitialization.areDolphinDirectoriesReady() &&
!activity.isChangingConfigurations
) {
flushUnsavedData()
}
}
override fun onActivityDestroyed(activity: Activity) {}
companion object {
@JvmStatic
external fun setBackgroundExecutionAllowedNative(allowed: Boolean)
@JvmStatic
external fun flushUnsavedData()
}
}

View File

@@ -5,6 +5,8 @@
#include "Common/Logging/Log.h"
#include "Core/AchievementManager.h"
#include "UICommon/UICommon.h"
#include "jni/Host.h"
extern "C" {
@@ -18,4 +20,11 @@ Java_org_dolphinemu_dolphinemu_utils_ActivityTracker_setBackgroundExecutionAllow
INFO_LOG_FMT(CORE, "SetBackgroundExecutionAllowed {}", allowed);
AchievementManager::GetInstance().SetBackgroundExecutionAllowed(allowed);
}
JNIEXPORT void JNICALL
Java_org_dolphinemu_dolphinemu_utils_ActivityTracker_flushUnsavedData(JNIEnv*, jclass)
{
HostThreadLock guard;
UICommon::FlushUnsavedData();
}
}