Make an empty game object in your Unity3D scene and add this script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class backButtonAndroid : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void FixedUpdate()
{
if (Application.platform == RuntimePlatform.Android)
{
if (Input.GetKey(KeyCode.Escape))
{
Application.Quit();
}
}
}
}
follow the instructions here if you do not know how to export the project to Android : https://medium.com/@angelhiadefiesta/integrate-a-unity-module-to-a-native-android-app-87644fe899e0
then go to YOUR APP in Android Studio and put android:process=":UnityKillsMe"
in your unity activity. It should look like this:
<activity android:label="@string/app_name" android:screenOrientation="fullSensor" android:launchMode="singleTask" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale|layoutDirection|density" android:hardwareAccelerated="false" android:name="com.yourpackageinfo.UnityPlayerActivity"
android:process=":UnityKillsMe">
<meta-data android:name="unityplayer.UnityActivity" android:value="true" />
</activity>
Ensure that android:launchMode="singleTask"
is there too.
Tested on Android 8.1 with Unity 2018.1 on Nexus 5x device including also Vuforia libraries for Unity.
hf