From 8b545a8ada78f8d41fb2d16dc3cc5446cbb8ed1f Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sat, 29 Jul 2023 10:47:34 -0400 Subject: [PATCH] Ensure to catch refreshed context on resume --- internal/driver/mobile/app/android.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/internal/driver/mobile/app/android.c b/internal/driver/mobile/app/android.c index 0d73683f4b..1eaaed344c 100644 --- a/internal/driver/mobile/app/android.c +++ b/internal/driver/mobile/app/android.c @@ -66,6 +66,14 @@ jint JNI_OnLoad(JavaVM* vm, void* reserved) { static int main_running = 0; +// ensure we refresh context on resume in case something has changed... +void processOnResume(ANativeActivity *activity) { + JNIEnv* env = activity->env; + setCurrentContext(activity->vm, (*env)->NewGlobalRef(env, activity->clazz)); + + onResume(activity); +} + // Entry point from our subclassed NativeActivity. // // By here, the Go runtime has been initialized (as we are running in @@ -119,7 +127,7 @@ void ANativeActivity_onCreate(ANativeActivity *activity, void* savedState, size_ // Note that onNativeWindowResized is not called on resize. Avoid it. // https://code.google.com/p/android/issues/detail?id=180645 activity->callbacks->onStart = onStart; - activity->callbacks->onResume = onResume; + activity->callbacks->onResume = processOnResume; activity->callbacks->onSaveInstanceState = onSaveInstanceState; activity->callbacks->onPause = onPause; activity->callbacks->onStop = onStop;