Resuming Application on Android with Unity

tvoloshyn picture tvoloshyn · Feb 19, 2014 · Viewed 8.8k times · Source

I'm trying to implement Pausing in Unity by using OnApplicationPause function.

It seems to work fine when I exit my game (on Android) by pressing home button and then comeback through list of active apps, but when I press the game icon on home screen, it restart the game instead of bringing me back.

Is there any way around this ?

Answer

Stanley picture Stanley · Jun 5, 2014

for me this was happening when I had an: android.os.DeadObjectException in the logs. (Meaning the application already died).

Check to see if you have something like this in your logs:

I/ActivityManager(  600): Restarting because process died: ActivityRecord{439f9588 u0 com.mycompany.myapp/com.unity3d.player.UnityPlayerProxyActivity}
W/ActivityManager(  600): Exception when starting activity com.mycompany.myapp/com.unity3d.player.UnityPlayerProxyActivity
W/ActivityManager(  600): android.os.DeadObjectException
W/ActivityManager(  600):   at android.os.BinderProxy.transact(Native Method)
W/ActivityManager(  600):   at android.app.ApplicationThreadProxy.scheduleLaunchActivity(ApplicationThreadNative.java:759)
W/ActivityManager(  600):   at com.android.server.am.ActivityStack.realStartActivityLocked(ActivityStack.java:1120)
W/ActivityManager(  600):   at com.android.server.am.ActivityStack.startSpecificActivityLocked(ActivityStack.java:1247)

...and if so look back even further in your logs to see why you app is dying. For me to keep the application from dying I had to move the intent filters:

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

from UnityPlayerProxyActivity to UnityPlayerNativeActivity