Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

App is restarted when re-launched

Discussion in 'Android' started by ironfiftynine, May 9, 2014.

  1. ironfiftynine

    ironfiftynine

    Joined:
    Jan 22, 2013
    Posts:
    69
    Good day. I have a unity android app which catches the event when it lost its focus to show a pause menu. However when I'm resuming the app after I press the home button, the app restarts. Tracing the logs in eclipse, onDestroy is called after resuming. I've read in my google searches that it's probably caused by the configChange tag in the manifest file, but I already included it in my project (See the code below).

    Code (csharp):
    1.  
    2. <?xml version="1.0" encoding="utf-8"?>
    3. <manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.ChronicleGames.DragonSnack" android:installLocation="preferExternal">
    4.   <uses-sdk android:minSdkVersion="9" android:targetSdkVersion="19" />
    5.   <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:smallScreens="true" android:xlargeScreens="true" />
    6.   <application android:icon="@drawable/app_icon" android:label="@string/app_name" android:debuggable="true">
    7.     <!-- Unity Activities -->
    8.     <activity android:label="@string/app_name" android:name="com.unity3d.player.UnityPlayerProxyActivity" android:screenOrientation="portrait" android:launchMode="singleTask" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale">
    9.       <intent-filter>
    10.         <action android:name="android.intent.action.MAIN" />
    11.         <category android:name="android.intent.category.LAUNCHER" />
    12.       </intent-filter>
    13.     </activity>
    14.     <activity android:label="@string/app_name" android:name="com.unity3d.player.UnityPlayerActivity" android:screenOrientation="portrait" android:launchMode="singleTask" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale">
    15.     </activity>
    16.     <activity android:label="@string/app_name" android:name="com.unity3d.player.UnityPlayerNativeActivity" android:screenOrientation="portrait" android:launchMode="singleTask" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale">
    17.       <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="false" />
    18.     </activity>
    19.     <activity android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" android:label="@string/app_name" android:name="com.unity3d.player.VideoPlayer" android:screenOrientation="portrait">
    20.     </activity>
    21.     <activity android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" android:name="com.google.example.games.pluginsupport.SignInHelperActivity" android:screenOrientation="portrait" android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" />
    22.     <activity android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" android:name="com.google.example.games.pluginsupport.SelectOpponentsHelperActivity" android:screenOrientation="portrait" android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" />
    23.     <activity android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" android:name="com.google.example.games.pluginsupport.InvitationInboxHelperActivity" android:screenOrientation="portrait" android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" />
    24.  
    25.     <!-- META-DATA -->
    26.     <meta-data android:name="com.google.android.gms.games.APP_ID" android:value="\ 410239958398" />
    27.     <meta-data android:name="com.google.android.gms.appstate.APP_ID" android:value="\ 410239958398" />
    28.     <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
    29.   </application>
    30.   <!-- PERMISSIONS -->
    31.   <uses-permission android:name="android.permission.INTERNET" />
    32.   <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    33.   <uses-feature android:glEsVersion="0x00020000" />
    34.   <supports-gl-texture android:name="GL_AMD_compressed_ATC_texture" />
    35.   <supports-gl-texture android:name="GL_ATI_texture_compression_atitc" />
    36.   <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    37.   <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    38.   <uses-feature android:name="android.hardware.sensor.accelerometer" />
    39.   <uses-feature android:name="android.hardware.touchscreen" />
    40.   <uses-feature android:name="android.hardware.touchscreen.multitouch" android:required="false" />
    41.   <uses-feature android:name="android.hardware.touchscreen.multitouch.distinct" android:required="false" />
    42. </manifest>
    43.  
    I also checked if the app is still running after I press the home button and it is still running which means the restart happens after the app receives its focus. Anything I missed in my manifest file or is it probably caused by another problem? Thank you very much.
     
  2. ironfiftynine

    ironfiftynine

    Joined:
    Jan 22, 2013
    Posts:
    69
    Figured it out. The intent-filter block should have been inside UnityPlayerNativeActivity and NOT UnityPlayerProxyActivity
     
  3. Enzign

    Enzign

    Joined:
    Aug 20, 2010
    Posts:
    169
    Awesome, fixed it for me as well. It seems like the default Unity AndroidManifest.xml has changed quite a bit and now only includes the UnityPlayerNativeActivity.
     
  4. brunity1312

    brunity1312

    Joined:
    Jun 10, 2022
    Posts:
    1
    thanks brother