HOME BUTTON on ANDROID: CRASH when clicking on home button and coming back to the app

Hi,

When I click on the home button on Android and try to come back in the app by clicking on the app icon, my app crashes after the “void AppDelegate::applicationWillEnterForeground()” fully executed.

The crash occurs with both Cocos2d-X SDK .10 and .11. I use NDK r7b.

Here are my applicationWillEnterForeground() and applicationDidEnterBackground() methods (nothing special…):

void AppDelegate::applicationDidEnterBackground()
{
    CCDirector::sharedDirector()->stopAnimation(); // I tried with and without this line ; crash in both cases

    CCLog("void AppDelegate::applicationDidEnterBackground() #1");

    CCDirector::sharedDirector()->pause();

     CCLog("void AppDelegate::applicationDidEnterBackground() #2");

    // if you use SimpleAudioEngine, it must be pause
    SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic(); // nota: I tried to remove all sounds in my app (and remove this line) ; same crash...

    CCLog("void AppDelegate::applicationDidEnterBackground() #3");
}

void AppDelegate::applicationWillEnterForeground()
{

    CCDirector::sharedDirector()->startAnimation(); // I tried with and without this line ; crash in both cases

    CCLog("void AppDelegate::applicationWillEnterForeground() #1");

    CCDirector::sharedDirector()->resume();

    CCLog("void AppDelegate::applicationWillEnterForeground() #2");

// if you use SimpleAudioEngine, it must resume here
     SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic(); // nota: I tried to remove all sounds in my app (and remove this line) ; same crash...

    CCLog("void AppDelegate::applicationWillEnterForeground() #3");


    // SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
}

The log is given below. As you can see, the crash occurs once applicationWillEnterForeground() is fully executed.

Any idea how to solve this issue ? Any big in SDK10 and SDK11 ?

Thanks…

02-29 10:08:54.830: I/ProvisionLog(290): [PhoneWindowManager] in interceptKeyBeforeDispatching(), KEYCODE_HOME, down=true mHomePressed=false canceled=false
02-29 10:08:54.880: I/InputReader(290): dispatchTouch::touch event's action is 1, pending(waiting finished signal)=0
02-29 10:08:54.880: I/InputDispatcher(290): Delivering touch to current input target: action: 1, channel '40a95820 StatusBar (server)'
02-29 10:08:54.880: I/InputDispatcher(290): Delivering touch to current input target: action: 1, channel 'TouchIntercepter (server)'
02-29 10:08:54.880: I/KeyguardViewMediator(290):  mShowing false mNeedToReshowWhenReenabled false
02-29 10:08:54.880: I/ProvisionLog(290): [KeyguardUpdateMonitor] in isDeviceProvisioned(), now return true
02-29 10:08:54.880: I/KeyguardViewMediator(290):  mShowing false mNeedToReshowWhenReenabled false
02-29 10:08:54.880: I/ProvisionLog(290): [KeyguardUpdateMonitor] in isDeviceProvisioned(), now return true
02-29 10:08:54.880: I/ProvisionLog(290): [PhoneWindowManager] in interceptKeyBeforeDispatching(), KEYCODE_HOME, down=false mHomePressed=true canceled=false
02-29 10:08:54.880: I/ProvisionLog(290): [PhoneWindowManager] in interceptKeyBeforeDispatching(), now call launchHomeFromHotKey()
02-29 10:08:54.880: I/ProvisionLog(290): [PhoneWindowManager] launchHomeFromHotKey() is called.
02-29 10:08:54.880: I/KeyguardViewMediator(290):  mShowing false mNeedToReshowWhenReenabled false
02-29 10:08:54.880: I/ProvisionLog(290): [KeyguardUpdateMonitor] in isDeviceProvisioned(), now return true
02-29 10:08:54.880: I/ProvisionLog(290): [PhoneWindowManager] in launchHomeFromHotKey(), now call startDockOrHome() #2
02-29 10:08:54.880: I/ProvisionLog(290): [PhoneWindowManager] in startDockOrHome(), now call startActivity(mHomeIntent)
02-29 10:08:54.880: I/ActivityManager(290): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10200000 cmp=com.android.launcher/com.android.launcher2.Launcher } from pid 290
02-29 10:08:54.970: D/MyApp(20349): protected void onPause() #1
02-29 10:08:54.980: D/dalvikvm(6678): GC_CONCURRENT freed 426K, 10% free 6521K/7175K, paused 3ms+3ms
*02-29 10:08:55.000: D/cocos2d-x debug info(20349): void AppDelegate::applicationDidEnterBackground() #1
02-29 10:08:55.000: D/cocos2d-x debug info(20349): void AppDelegate::applicationDidEnterBackground() #2
02-29 10:08:55.000: D/cocos2d-x debug info(20349): void AppDelegate::applicationDidEnterBackground() #3*
02-29 10:08:55.040: D/MyApp(20349): protected void onPause() #2
02-29 10:08:55.040: D/WindowManager(290): Setting visibility of AppWindowToken{40b830c8 token=ActivityRecord{40bacec0 com.android.launcher/com.android.launcher2.Launcher}}: true
02-29 10:09:19.490: I/ActivityManager(290): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.ag.games.js/.TestsDemo } from pid 20434
02-29 10:09:19.540: W/SocialHubWidget(447): [SocialHubWidgetProvider] onReceive() >>  
02-29 10:09:19.540: W/SocialHubWidget(447): [SocialHubWidgetProvider] ===== >> ==================================================
02-29 10:09:19.540: W/SocialHubWidget(447): [SocialHubWidgetProvider] action >> action : sec.android.intent.action.HOME_PAUSE
02-29 10:09:19.540: D/WindowManager(290): Setting visibility of AppWindowToken{4277e9e0 token=ActivityRecord{419d0c08 com.ag.games.js/.TestsDemo}}: true
02-29 10:09:19.550: D/MyApp(20349): protected void onResume()  #1
02-29 10:09:19.550: D/MyApp(20349): protected void onResume()  #2
02-29 10:09:19.550: D/cocos2d-x debug info(20349): void AppDelegate::applicationWillEnterForeground() #1
02-29 10:09:19.550: D/cocos2d-x debug info(20349): void AppDelegate::applicationWillEnterForeground() #2
02-29 10:09:19.550: D/cocos2d-x debug info(20349): void AppDelegate::applicationWillEnterForeground() #3
02-29 10:09:19.550: I/SurfaceFlinger(224): id=675(3) createSurface 0x13b2ec for pid 20349 (1280x752),4 flag=0, SurfaceView
02-29 10:09:19.910: I/DEBUG(17690): Build fingerprint: 'samsung/GT-P7510/GT-P7510:3.1/HMJ37/XWKI2:user/release-keys'
02-29 10:09:19.910: I/DEBUG(17690): pid: 20349, tid: 20360  >>> com.ag.games.js <<<
02-29 10:09:19.910: I/DEBUG(17690): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 5ead2008
02-29 10:09:19.910: I/DEBUG(17690):  r0 5d820000  r1 5ead2008  r2 00002000  r3 00000010
02-29 10:09:19.910: I/DEBUG(17690):  r4 00020000  r5 00000010  r6 5d820000  r7 5ead2008
02-29 10:09:19.910: I/DEBUG(17690):  r8 00000800  r9 00020000  10 00002000  fp 00000200
02-29 10:09:19.910: I/DEBUG(17690):  ip 00000200  sp 5c41a87c  lr 5ead4008  pc 82603eac  cpsr 20000010
02-29 10:09:19.910: I/DEBUG(17690):  d0  000084c047012f00  d1  461c00004704c080
02-29 10:09:19.910: I/DEBUG(17690):  d2  461c0800461c0400  d3  c2700000461c0c00
02-29 10:09:19.910: I/DEBUG(17690):  d4  4704c000c26f3f7c  d5  41500000000084c0
02-29 10:09:19.910: I/DEBUG(17690):  d6  7f7fffffffffffc3  d7  0000812fff7fffff
02-29 10:09:19.910: I/DEBUG(17690):  d8  0000000000000000  d9  0000000000000000
02-29 10:09:19.910: I/DEBUG(17690):  d10 0000000000000000  d11 0000000000000000
02-29 10:09:19.910: I/DEBUG(17690):  d12 0000000000000000  d13 0000000000000000
02-29 10:09:19.910: I/DEBUG(17690):  d14 0000000000000000  d15 0000000000000000
02-29 10:09:19.910: I/DEBUG(17690):  scr 80000012
02-29 10:09:20.060: I/DEBUG(17690):          #00  pc 00003eac  /system/lib/egl/libGLESv2_tegra.so
02-29 10:09:20.060: I/DEBUG(17690):          #01  lr 5ead4008  
02-29 10:09:20.060: I/DEBUG(17690): libc base address: aff00000
02-29 10:09:20.060: I/DEBUG(17690): code around pc:
02-29 10:09:20.060: I/DEBUG(17690): 82603e8c e5bcf6c8 e28fc600 e28cca49 e5bcf6c0 
02-29 10:09:20.060: I/DEBUG(17690): 82603e9c 00000000 e92d4ff0 e59dc024 e081e002 
02-29 10:09:20.060: I/DEBUG(17690): 82603eac e8b10330 e8be0cc0 f5d1f040 f5def040 
02-29 10:09:20.060: I/DEBUG(17690): 82603ebc e25cc001 e8800ff0 e2800c01 1afffff7 
02-29 10:09:20.060: I/DEBUG(17690): 82603ecc e59dc024 e2800020 e2533002 e040040c 
02-29 10:09:20.060: I/DEBUG(17690): code around lr:
02-29 10:09:20.060: I/DEBUG(17690): 5ead3fe8 ffffffff ffffffff ffffffff ffffffff 
02-29 10:09:20.060: I/DEBUG(17690): 5ead3ff8 ffffffff ffffffff ffffffff ffffffff 
02-29 10:09:20.060: I/DEBUG(17690): 5ead4008 ffffffff ffffffff ffffffff ffffffff 
02-29 10:09:20.060: I/DEBUG(17690): 5ead4018 ffffffff ffffffff ffffffff ffffffff 
02-29 10:09:20.060: I/DEBUG(17690): 5ead4028 ffffffff ffffffff ffffffff ffffffff 
02-29 10:09:20.060: I/DEBUG(17690): stack:
02-29 10:09:20.060: I/DEBUG(17690):     5c41a83c  00001000  
02-29 10:09:20.060: I/DEBUG(17690):     5c41a840  001c1008  
02-29 10:09:20.060: I/DEBUG(17690):     5c41a844  00000005  
02-29 10:09:20.060: I/DEBUG(17690):     5c41a848  8264d0d8  
02-29 10:09:20.060: I/DEBUG(17690):     5c41a84c  00000400  
02-29 10:09:20.060: I/DEBUG(17690):     5c41a850  cc75fea0  
02-29 10:09:20.060: I/DEBUG(17690):     5c41a854  00000000  
02-29 10:09:20.060: I/DEBUG(17690):     5c41a858  00000000  
02-29 10:09:20.060: I/DEBUG(17690):     5c41a85c  5c41a92c  
02-29 10:09:20.060: I/DEBUG(17690):     5c41a860  0032e694  
02-29 10:09:20.060: I/DEBUG(17690):     5c41a864  82628200  /system/lib/egl/libGLESv2_tegra.so
02-29 10:09:20.060: I/DEBUG(17690):     5c41a868  826259b8  /system/lib/egl/libGLESv2_tegra.so
02-29 10:09:20.060: I/DEBUG(17690):     5c41a86c  8264dfb4  
02-29 10:09:20.060: I/DEBUG(17690):     5c41a870  df002777  
02-29 10:09:20.060: I/DEBUG(17690):     5c41a874  e3a070ad  
02-29 10:09:20.060: I/DEBUG(17690):     5c41a878  00000000  
02-29 10:09:20.060: I/DEBUG(17690): #00 5c41a87c  00020000  
02-29 10:09:20.060: I/DEBUG(17690):     5c41a880  00000010  
02-29 10:09:20.060: I/DEBUG(17690):     5c41a884  5d820000  
02-29 10:09:20.060: I/DEBUG(17690):     5c41a888  5ead2008  
02-29 10:09:20.060: I/DEBUG(17690):     5c41a88c  00000800  
02-29 10:09:20.060: I/DEBUG(17690):     5c41a890  00020000  
02-29 10:09:20.060: I/DEBUG(17690):     5c41a894  00002000  
02-29 10:09:20.060: I/DEBUG(17690):     5c41a898  00000200  
02-29 10:09:20.060: I/DEBUG(17690):     5c41a89c  82626cc4  /system/lib/egl/libGLESv2_tegra.so
02-29 10:09:20.060: I/DEBUG(17690):     5c41a8a0  00000200  
02-29 10:09:20.060: I/DEBUG(17690):     5c41a8a4  81d05f01  /system/lib/libnvrm.so
02-29 10:09:20.060: I/DEBUG(17690):     5c41a8a8  81d05f29  /system/lib/libnvrm.so
02-29 10:09:20.060: I/DEBUG(17690):     5c41a8ac  00000002  
02-29 10:09:20.060: I/DEBUG(17690):     5c41a8b0  5c41a94c  
02-29 10:09:20.060: I/DEBUG(17690):     5c41a8b4  5c41a9dc  
02-29 10:09:20.060: I/DEBUG(17690):     5c41a8b8  0032e4c0  
02-29 10:09:20.060: I/DEBUG(17690):     5c41a8bc  00000800  
02-29 10:09:20.060: I/DEBUG(17690):     5c41a8c0  5d820000  
02-29 10:09:22.100: I/DEBUG(17690): dumpstate /data/log/dumpstate_app_native.txt
02-29 10:09:22.700: V/AudioHardware(227): AudioStreamOutALSA::standby
02-29 10:09:22.700: D/AudioHardware(227): AudioHardware pcm playback is going to standby.
02-29 10:09:22.700: V/AudioHardware(227): closeMixer_l() mMixerOpenCnt: 1
02-29 10:09:22.700: I/alsa_mixer(227): mixer_close
02-29 10:09:22.700: V/AudioHardware(227): closeMixer_l mMixerOpenCnt = 0 end
02-29 10:09:22.700: I/AudioHardware(227): closePcmOut_l() mPcmOpenCnt: 1
02-29 10:09:22.700: V/alsa_pcm(227): pcm_close
02-29 10:09:22.700: V/alsa_pcm(227): real pcm_close
02-29 10:09:22.700: V/AudioHardware(227): closePcmOut_l end
02-29 10:09:29.080: I/dumpstate(20692): done
02-29 10:09:29.140: I/ActivityManager(290): Process com.ag.games.js (pid 20349) has died.
02-29 10:09:29.140: D/WindowManager(290): Setting visibility of AppWindowToken{4277e9e0 token=ActivityRecord{419d0c08 com.ag.games.js/.TestsDemo}}: false
02-29 10:09:29.140: D/WindowManager(290): Setting visibility of AppWindowToken{40b830c8 token=ActivityRecord{40bacec0 com.android.launcher/com.android.launcher2.Launcher}}: true
02-29 10:09:29.150: D/Zygote(225): Process 20349 terminated by signal (11)
02-29 10:09:29.150: E/InputDispatcher(290): channel '4179a3c8 com.ag.games.js/com.ag.games.js.TestsDemo (server)' ~ Consumer closed input channel or an error occurred.  events=0x8
02-29 10:09:29.150: E/InputDispatcher(290): channel '4179a3c8 com.ag.games.js/com.ag.games.js.TestsDemo (server)' ~ Channel is unrecoverably broken and will be disposed!
02-29 10:09:29.150: I/SurfaceFlinger(224): id=675 Removed SurfaceView idx=1 Map Size=2
02-29 10:09:29.150: I/SurfaceFlinger(224): id=675 Removed SurfaceView idx=-2 Map Size=2
02-29 10:09:29.150: D/gralloc(224): Attempting to delete a locked buffer!
02-29 10:09:29.150: D/gralloc(224): Buffer 27 locks: (tid = 20360 (x1), usage = 0x200)
02-29 10:09:29.150: I/WindowManager(290): WINDOW DIED Window{4179a3c8 com.ag.games.js/com.ag.games.js.TestsDemo paused=false}
02-29 10:09:29.150: W/WindowManager(290): Force-removing child win Window{4196ad98 SurfaceView paused=false} from container Window{4179a3c8 com.ag.games.js/com.ag.games.js.TestsDemo paused=false}
02-29 10:09:29.160: I/SurfaceFlinger(224): id=676(103) createSurface 0x13751c for pid 20434 (1280x752),1 flag=0, com.android.launcher/com.android.launcher2.Launcher
02-29 10:09:29.160: W/WindowManager(290): Failed looking up window
02-29 10:09:29.160: W/WindowManager(290): java.lang.IllegalArgumentException: Requested window android.os.BinderProxy@427317c8 does not exist
02-29 10:09:29.160: W/WindowManager(290):   at com.android.server.wm.WindowManagerService.windowForClientLocked(WindowManagerService.java:6731)
02-29 10:09:29.160: W/WindowManager(290):   at com.android.server.wm.WindowManagerService.windowForClientLocked(WindowManagerService.java:6722)
02-29 10:09:29.160: W/WindowManager(290):   at com.android.server.wm.WindowState$DeathRecipient.binderDied(WindowState.java:1343)
02-29 10:09:29.160: W/WindowManager(290):   at android.os.BinderProxy.sendDeathNotice(Binder.java:385)
02-29 10:09:29.160: W/WindowManager(290):   at dalvik.system.NativeStart.run(Native Method)
02-29 10:09:29.160: I/WindowManager(290): WIN DEATH: null
02-29 10:09:29.160: W/WindowManager(290): Failed looking up window
02-29 10:09:29.160: W/WindowManager(290): java.lang.IllegalArgumentException: Requested window android.os.BinderProxy@41bd0198 does not exist
02-29 10:09:29.160: W/WindowManager(290):   at com.android.server.wm.WindowManagerService.windowForClientLocked(WindowManagerService.java:6731)
02-29 10:09:29.160: W/WindowManager(290):   at com.android.server.wm.WindowManagerService.windowForClientLocked(WindowManagerService.java:6722)
02-29 10:09:29.160: W/WindowManager(290):   at com.android.server.wm.WindowState$DeathRecipient.binderDied(WindowState.java:1343)
02-29 10:09:29.160: W/WindowManager(290):   at android.os.BinderProxy.sendDeathNotice(Binder.java:385)
02-29 10:09:29.160: W/WindowManager(290):   at dalvik.system.NativeStart.run(Native Method)
02-29 10:09:29.160: I/WindowManager(290): WIN DEATH: null
02-29 10:09:29.180: E/TODmobile(2134): onReceive action=sec.android.intent.action.HOME_RESUME
02-29 10:09:29.180: E/TODmobile(2134): hour : 10    minute : 09
02-29 10:09:29.180: E/DigitalClockWidget(2134): updateWidgets
02-29 10:09:29.180: E/TODmobile(2134): hour : 10    minute : 09

Hi!
we’ve got a very similar problem here, although the helloWorld works well.

Did you solve this issue?

thanks for your help!

Even I am having the same issue. Has anybody resolved this yet?

I have a similar problem. My game doesn’t come back on some devices. Do I need to reload resources after background-state? It’s strange that - on some devices it works fine, on others (I think it’s cheap devices) - not.

yeah it happens to me sometimes and on some devices. anybody got any solution???

Interesting — what version of Android?

Did you translate that tombstone to find out which line?