Android applicationDidEnterBackground not called v3.13.1

Having an issue with 3.13.1, for android applicationDidEnterBackground is not called when it should have.

While with iPhone my game music is paused and animation is stopped, on my android phone 5.1 and samsung tablet android 4.4.2 the music tracks I play in my app continue playing while for example reading my mail on the device.

Am I the only one who has this problem? I found some fixed issues regarding this issue back in 2011 #462 #238 [android]. In Cocos2dxGLSurfaceView.java:
@Override
public void onPause() {
this.queueEvent(new Runnable() {
@Override
public void run() {
Cocos2dxGLSurfaceView.this.mCocos2dxRenderer.handleOnPause();
}
});
this.setRenderMode(RENDERMODE_WHEN_DIRTY);
//super.onPause();
}
I was thinking to fix it by uncommmenting the last line super.onPause() but that didn’t work unfortunately, the code is different than the change of 2011, it had the super.onPause().
Can you please have a look at this?

Your AppDelegate.cpp should look like this:

// This function will be called when the app is inactive. Note, when receiving a phone call it is invoked.
void AppDelegate::applicationDidEnterBackground() {
    Director::getInstance()->stopAnimation();

    // if you use SimpleAudioEngine, it must be paused
    CocosDenshion::SimpleAudioEngine::getInstance()->pauseBackgroundMusic();
}

// this function will be called when the app is active again
void AppDelegate::applicationWillEnterForeground() {
    Director::getInstance()->startAnimation();

    // if you use SimpleAudioEngine, it must resume here
    CocosDenshion::SimpleAudioEngine::getInstance()->resumeBackgroundMusic();
}

You must tell audio engine to pause/resume music.

thanks, but that is not my question. I already have this code, ios is working but not for android.

I reported a issue ‘applicationDidEnterBackground not called for Android’ #17213

This issue is still not solved! Typical thing is that applicationWillEnterForeground is in fact called but applicationDidEnterBackground not. I discovered this because the music didn’t pause. Of course when somebody’s phone is ringing this can be quite annoying, also the battery life goes down the drain like this when you don’t close the application.
How can it be that I am the only one that is aware of this issue for android?!

1 Like