cocos2d-x
cocos2d-x copied to clipboard
Black screen after unlocking Android device
- cocos2d-x version: 3.17.2 and 4.0
- devices test on: Samsung A51, S20 with Android 11
- developing environments
- NDK version: 21.3.6528147 (doesn't matter)
Steps to Reproduce:
- Launch a game
- Lock a device with fingerprint sensor
- Unlock by a finger
The issue is with isDeviceLocked method of Cocos2dxActivity and KeyguardManager. inKeyguardRestrictedInputMode, isKeyguardLocked and isDeviceLocked methods of KeyguardManager can have delay and can return wrong values, when onResume or onWindowFocusChanged methods are called.
So isDeviceLocked often return true during onWindowFocusChanged is called or even in sometime after, that's why mGLSurfaceView.onResume() isn't called and black screen is happened.
I encountered this issue too.
maybe we can call mGLSurfaceView.onResume() in Activity's onResume, but I don't know why the author create resumeIfHasFocus for onResume
Edit:
I call Cocos2dxHelper.onResume(); and mGLSurfaceView.onResume(); in Activity's onResume and the problem is solved.
@atship Activity's onResume can be called while the game is in background. So it's not safe to call mGLSurfaceView.onResume() directly from it. I suggest to comment out isDeviceLocked method using in resumeIfHasFocus method.