Search code examples
androidandroid-activitycocos2d-x

how to handle android low battery popup interrupt?


I have game in cocos2d-x 3.4 I have problem with low battery pop-up & title bar interruption. On this two interrupt onPause()/onResume() is not getting called.

So do i have to handle this with any other activity method or what?

Thank you.


Solution

  • So here is the answer if anyone needs it in future,

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
    
        if(hasFocus) {
            // Resume logic
            Cocos2dxHelper.onResume();
            this.mGLSurfaceView.onResume();
        }
        else {
            // Pause logic
            Cocos2dxHelper.onPause();
            this.mGLSurfaceView.onPause();
        }
    }
    

    It will work for low battery pop-up notification as well as for Title bar dragging interruption.