- Home /
Simple Android project shuts down when user presses the Recent Apps button
The game shuts down when the user presses the Recent Apps button or changes focus to another app. I created a blank minimal project (attached) to see if it was the game code that was causing it but it does the same thing. I'm assuming that there is something I need to add to the Android manifest, but so far nothing I have found has fixed the issue. I have tried android:alwaysRetainTaskState="true" and android:clearTaskOnLaunch="false"
The memory use on the test project is minimal so it can't be being killed to release memory. Any ideas on how to fix this?
Test App
A new Unity project that contains no additional assets other than a test script. There is a text element in the center of the screen that is managed by the script which changes it based on app state and slowly rotates it so you can see that it is still running. The background color changes based on state so it can be seen even when the message is covered.
Behavior
All tests done with the debugger attached.
- The app can lose and gain focus via the notification bar with no issues. 
- The app survives when locking and unlocking the phone even over extended periods. 
- About one second after the user presses the Recent Apps or Home button the game is terminated and the debugger is disconnected. A breakpoint set on OnApplicationPause does get hit, but then the debugger closes. 
 
Notable Output
 18.890  1347  4861 D     ActivityManager: mDVFSHelper.acquire()
 18.900  1347  4861 D     InputDispatcher: Focused application set to: xxxx
 18.900  1347  4861 D     InputDispatcher: Focus left window: 9097
 ...
 18.980  9097  9097 V     ActivityThread: updateVisibility : ActivityRecord{2dcddff token=android.os.BinderProxy@1aec36c {com.unityandroidtest.focus/com.unity3d.player.UnityPlayerActivity}} show : false
 18.980  2368  2368 D     SecWifiDisplayUtil: Metadata value : SecSettings2
 18.990  1347  1357 I     art     : Background partial concurrent mark sweep GC freed 47183(2MB) AllocSpace objects, 4(80KB) LOS objects, 25% free, 46MB/62MB, paused 1.648ms total 117.852ms
 18.990  1347  1502 D     ActivityManager: post active user change for 0 fullscreen true isFloatingActivity() false isHomeActivity() false
 18.990  1347  1502 D     KnoxTimeoutHandler: postActiveUserChange [MsgParam] userId: 0 fullscreen is true showWhenlocked is false
 18.990   971  1476 V     audio_hw_primary: out_get_latency: Latency 80
 18.990  2368  2368 D     ScoverManager: unregisterListener
 18.990  1347  1347 D     KnoxTimeoutHandler: handleActiveUserChange [MsgParam] userId: 0 fullscreen is true showWhenlocked is false
 18.990  1347  2470 D     CoverManagerWhiteLists: isAllowedToUse : SIGNATURE_MATCH
 18.990  1347  2723 D     CoverManagerWhiteLists: isAllowedToUse : SIGNATURE_MATCH
 18.990  1347  2723 D     CoverManager.StateNotifier: unregisterCallback : binder = android.os.BinderProxy@5c1130d, pid : 2368, uid : 10062
 18.990  2368  2368 D     ScoverManager: registerListener
 18.990  1347  2621 D     CoverManagerWhiteLists: isAllowedToUse : SIGNATURE_MATCH
 18.990  1347  2763 D     CoverManagerWhiteLists: isAllowedToUse : SIGNATURE_MATCH
 18.990  1347  2763 D     CoverManager.StateNotifier: registerListenerCallback : binder = android.os.BinderProxy@fdd2c10, pid : 2368, uid : 10062, type : 1
 18.990  1347  1347 I     KnoxTimeoutHandler: Shared devices show user statefalse
 18.990  2368  2368 D     Recents_RecentsActivity: onPause
 18.990  2368  2368 D     Recents_RecentsActivity: onNewIntent
 18.990  2368  2368 D     Recents_RecentsActivity: onResume
 19.000   971  1476 V     audio_hw_primary: out_get_latency: Latency 80
 19.000  2368  2368 D     View    : mTwDrawDuringWindowsAnimating=true
 19.000  2368  2368 D     MultiPhoneWindow: performUpdateVisibility, same visibility false
 19.010   971  1476 V     audio_hw_primary: out_get_latency: Latency 80
 19.010  9097  9097 I     Process : Sending signal. PID: 9097 SIG: 9
 Some additional information (9/19)
I have been testing on a Galaxy S7 (SM-G930V Android version 6.0.1 API 23 64bit).
I exported the Unity project to Android studio and have debugged it both on the device and in emulation (Nexus 5X Android version 6.0 API 23 x86 64bit).
On the emulator it works fine and I can step through every part the OnPause call.
On the device it crashes at some point after the super.OnPause call from OnPause in UnityPlayerActivity.java and I can't step through because the source lines don't match the calls being made. For example stepping into OnPause goes to OnDestroy and at some point steps into a function called handlePause() that is not in the android SDK yet it says is in android\view\Window.java.
 Eventually it calls enqueMessage with msg = { when=-10d1h27m59s804ms what=2269 obj=PAUSE target=android.os.Handler } after which it crashes.
I'm still debugging this, but I'm hoping that someone has gone down this particular rabbit hole so I can get past this.
I'm probably missing something but have you actually confirmed that it is crashing, and at that particular point? (rather than, for example, when the app gets paused).
And sorry this probably isn't very useful but can you confirm that other apps do stay active? I'm only asking because someone I was working with once spent ages trying to work out the cause of similar behaviour, only to eventually realise they'd got "Don't keep activities" set to true in their android Developer Settings
Answer by AltairHVS · Sep 20, 2016 at 03:51 PM
The "Do not keep activities" developer setting was the problem. Thank you!
That seems like a dangerous setting to have defaulted to ON and at the very bottom of a long list.
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                