Mobile game restarts when using Application.Quit

自古美人都是妖i 提交于 2019-12-05 18:44:27

So, it all went back to Unity5 and how it integrates older plugins like Admob. Apparently, there is no ProxyActivity needed anymore for Android builds. So I completely removed the following out of the AndroidManifest.xml file:

<activity android:name="com.unity3d.player.UnityPlayerProxyActivity" android:label="@string/app_name" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" >
<meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="true" />
  <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
  </intent-filter>
</activity>

And then moved the <intent-filter> into the UnityPlayerActivity:

  <activity android:name="com.unity3d.player.UnityPlayerActivity" android:label="@string/app_name" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" >
  <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
  </intent-filter>
</activity>

Now Application.Quit() works no problem!

Complete AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="preferExternal" package="com.example.admobtest" android:versionName="1.0" android:versionCode="1">
  <supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true" android:anyDensity="true" />
  <!-- Mobile Ads Permissions -->
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
  <application android:icon="@drawable/app_icon" android:label="@string/app_name" android:debuggable="false">
    <!-- meta-data tag for Google Play services -->
    <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"/>
    <activity android:name="com.unity3d.player.UnityPlayerActivity" android:label="@string/app_name" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" >
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
    </activity>
    <activity android:name="com.unity3d.player.UnityPlayerNativeActivity" android:label="@string/app_name" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" >
      <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="true" />
      <meta-data android:name="android.app.lib_name" android:value="unity" />
    </activity>
    <activity android:name="com.unity3d.player.VideoPlayer" android:label="@string/app_name" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" >
    </activity>
    <!-- Google Mobile Ads Activity -->
    <activity android:name="com.google.android.gms.ads.AdActivity"
              android:label="@string/app_name"
              android:theme="@android:style/Theme.Translucent"
              android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
    </activity>
    <!-- PurpleBrain AdBuddiz Activity -->
    <activity android:name="com.purplebrain.adbuddiz.sdk.AdBuddizActivity"
              android:label="@string/app_name"
              android:theme="@android:style/Theme.Translucent">
    </activity>
  </application>
  <uses-feature android:glEsVersion="0x00020000" />
  <uses-sdk android:minSdkVersion="9" android:targetSdkVersion="19" />
</manifest>

@theprisoner6 aswer doesn't work for me but for reference the another option is to hide an application (move it to back). This has added value that if the Android decide it is worth to keep the app in memory you will avoid loading an application which should improve user experience. This could be handled as a plugin but hey, there is no need for that! Very simple C# code:

    AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
    AndroidJavaObject jo = jc.GetStatic<AndroidJavaObject>("currentActivity");
    var movedToBack = jo.Call<bool>("moveTaskToBack", true);

Swap that code with Application.Quit() and you are done.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!