Resolution problem while launching game through push notification from lock screen

Resolution problem while launching game through push notification from lock screen
0.0 0



I am using Batch framework to integrate Push notification into my game.
Everything is fine with iOS.
In Android it works fine but i have one bug.
If device is locked when push notification comes on that time game launched with width/height swapped.

my mobile res is 1920 x 1080 and my game is in landscape mode

Below method is called twice in

protected void onSizeChanged( ... )

first with width : 1080 height : 1920
second width : 1920 height : 1080

So game is starting with first config, but it should start with second.

Any thoughts, any help?
BTW Batch officially doesn’t support cocos2d-x so there are not helping, but i am still using it as its free and easy to integrate.


Quarter screen on android

I’ve noticed this too. It can easily be reproduced by launching an app from Eclipse/Android Studio while phone is locked.


So i modified onSizeChanged method in as below
Note: Do this if your game is in landscape mode.

    protected void onSizeChanged(final int pNewSurfaceWidth, final int pNewSurfaceHeight, final int pOldSurfaceWidth, final int pOldSurfaceHeight) {
        if(!this.isInEditMode()) {
               if(pNewSurfaceWidth < pNewSurfaceHeight)
                       this.mCocos2dxRenderer.setScreenWidthAndHeight(pNewSurfaceHeight, pNewSurfaceWidth); 
            	this.mCocos2dxRenderer.setScreenWidthAndHeight(pNewSurfaceWidth, pNewSurfaceHeight);

Everything downscaled!
Android 7.1 Graphics Issues

Hi, this is troublesome issue.

And solution is quite not perfect.

  1. You have to modify file outside project - after cocos2d-x update you can forget changing it.
    Solution: do not forget :smiley:

  2. There’s no way to determine in this place in code if game is landscape or portrait. I have many projects, which import this one. Some are landscape, other portrait.
    Solution: make 2 projects landscape or portrait

  3. Worst issue: I have virtual navigation buttons on my screen. So first time (when launching from locked screen, so bug should appear) I can see in logs:

06-30 15:34:21.090: I/System.out(1375): onSizeChanged, from: 0, 0, to: 1080, 1920

And game is initializing even after correcting width and height in 1920x1080 resolution, but this is incorrect and I can see virtual navigation keys overlapping part of the game.
Just a second later I can see second call:

06-30 15:34:21.970: I/System.out(1375): onSizeChanged, from: 1080, 1920, to: 1794, 1080

but it’s too late, game is already created in wrong resolution. It should somehow refresh.

If I normally run the game I can see from: 0, 0 to 1794, 1080 and in this situation everything is ok.
Also you have reproduce it another way: rotate your phone to portrait, tap app to run it and immediately lock screen. Before it’ll launch it won’t have time to rotate and bug will appear.

Solution: game should reinitialize after changing orientation?

That’s strange, because it should run always in landscape from the start:


this I can find in my manifest file associated with org.cocos2dx.cpp.AppActivity.


Well i dont have this issue.
And i am not using virtual navigation so i dont have any other issue as of now.
But yes indeed, game should reinitialize after changing orientation

Its Android :smile:


But most android used phones have virtual navigation (except samsung). So this is serious issue.


I have to test on one of the device.


Anyone knows how to fix this?


Bump! This bug sucks :slight_smile:


@smitpatel88 solution is working


We are seeing this bug too. Did anyone find a solution compatible with virtual navigation?


It works with it no problem :slight_smile: I mean @smitpatel88 solution.



It’s work! Thank you sooooooooo much~


Welcome :slight_smile: