From 3a3b8996362d84232e09b745ddc9bffade520c61 Mon Sep 17 00:00:00 2001 From: rh101 Date: Tue, 17 May 2022 14:02:02 +1000 Subject: [PATCH] Fix Android screen blank issue after unlocking device with application running. --- .../org/cocos2dx/lib/Cocos2dxActivity.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/core/platform/android/java/src/org/cocos2dx/lib/Cocos2dxActivity.java b/core/platform/android/java/src/org/cocos2dx/lib/Cocos2dxActivity.java index c51134378b..8b230be3bc 100644 --- a/core/platform/android/java/src/org/cocos2dx/lib/Cocos2dxActivity.java +++ b/core/platform/android/java/src/org/cocos2dx/lib/Cocos2dxActivity.java @@ -171,8 +171,9 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe Log.d(TAG, "onResume()"); paused = false; super.onResume(); - this.hideVirtualButton(); - resumeIfHasFocus(); + if (this.hasFocus) { + resume(); + } } @Override @@ -181,7 +182,15 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe super.onWindowFocusChanged(hasFocus); this.hasFocus = hasFocus; - resumeIfHasFocus(); + if (this.hasFocus && !paused) { + resume(); + } + } + + private void resume() { + this.hideVirtualButton(); + Cocos2dxHelper.onResume(); + mGLSurfaceView.onResume(); } private void resumeIfHasFocus() { @@ -190,9 +199,7 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe boolean readyToPlay = !isDeviceLocked() && !isDeviceAsleep(); if(hasFocus && readyToPlay) { - this.hideVirtualButton(); - Cocos2dxHelper.onResume(); - mGLSurfaceView.onResume(); + resume(); } }