Resuming Android Application with Unity

I am trying to implement Pausing in Unity using the OnApplicationPause function.

It seems to work fine when I exit my game (on Android) by pressing the home button and then return through the list of active applications, but when I click the game icon on the main screen, it restarts the game instead of returning me back .

Is there any way around this?

+6
source share
5 answers

for me, this happened when I had: android.os.DeadObjectException in the logs. (The value of the application has already died).

Check if you have something similar 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 you look back so much in your magazines to find out why you are dying. 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

+7
source

It should resume when you return to the game. If not, then your game stream will automatically restart when it returns from pause.

In your game, try checking the status of OnApplicationPause and debug from there. Sample code is in this thread http://answers.unity3d.com/questions/286939/detecting-when-applicationdidbecomeactive-in-unity.html

0
source

In my experience, these strange things happen when you do not have all the necessary information in your AndroidManifest.xml file. In particular, this line:

 <activity android:name="your_name_here.Activity" android:label="@string/app_name" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" android:screenOrientation="your_orientation_here_if_needed"> 

Make sure "android: configChanges" is located here. Otherwise, to provide you with more specific information, you will need to tell logcat when this will happen.

0
source

You check the launch mode on the android manifest and get a value similar to this android: launchMode = "singleTask"

0
source

Did you try to manipulate the life cycle of your application when you exported it as an Android project?

You can do this (in Unity 2018.4.5 other versions may differ) by ticking the item “Export project” in “File” - “Build settings” and clicking “Export”. You can open the resulting gradle project, for example, in Android Studio and find UnityPlayerActivity in the following situation:

  // Pause @Override protected void onPause() { super.onPause(); mUnityPlayer.pause(); } // Resume Unity @Override protected void onResume() { super.onResume(); mUnityPlayer.resume(); } @Override protected void onStart() { super.onStart(); mUnityPlayer.start(); } @Override protected void onStop() { super.onStop(); mUnityPlayer.stop(); } // Low Memory Unity @Override public void onLowMemory() { super.onLowMemory(); mUnityPlayer.lowMemory(); } // Trim Memory Unity @Override public void onTrimMemory(int level) { super.onTrimMemory(level); if (level == TRIM_MEMORY_RUNNING_CRITICAL) { mUnityPlayer.lowMemory(); } } 

I have no experience with this, but wanted to show you the opportunity :)

0
source

All Articles