Cocos and Activity interactive page black screen

After the Cocos game is nested on the Android page, the Android dialog is on the top, and the cocos game interface is on the bottom;
lock the screen or switch to the background, and then reopen the App, the dialog background will turn black, but the Android interface dialog will be displayed normally.


solution: 

Add the following code to Cocos2dxActivity to solve it.

@Override
protected void onRestart() {
    super.onRestart();
    Cocos2dxHelper.onResume();
    mGLSurfaceView.onResume();
}
@Override
protected void onStop() {
    super.onStop();
    Cocos2dxHelper.onPause();
    mGLSurfaceView.onPause();
}

Comparison of renderings:

normal display:

Black screen effect after locking the screen or switching between the front and back:

Principle analysis:

The Cocos2dxActivity class life cycle monitoring of Cocos games, after the SDK interface pops up, the screen is locked or the front and back switches are repeatedly switched. Its statement cycle is as follows, in essence, it is because Cocos2dxActivity does not execute OnPause() when switching to the background, and does not execute onRessume() when restarting The life cycle causes the game page to fail to render, so the screen will be black.

Guess you like

Origin blog.csdn.net/zhao8856234/article/details/125766989