cocos2d-x icon indicating copy to clipboard operation
cocos2d-x copied to clipboard

Black screen after unlocking Android device

Open ondesly opened this issue 4 years ago • 2 comments
trafficstars

  • 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:

  1. Launch a game
  2. Lock a device with fingerprint sensor
  3. 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.

ondesly avatar Feb 16 '21 12:02 ondesly

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 avatar Feb 20 '21 03:02 atship

@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.

ondesly avatar Feb 20 '21 07:02 ondesly