Search Unity

Android back button

Discussion in 'Android' started by Schumaker, Jun 30, 2018.

  1. Schumaker

    Schumaker

    Joined:
    Jul 14, 2016
    Posts:
    40
    Hello,

    I'm getting mad to proper map and use de back button of android. I tried 3 codes that I found on the web and nothing. Any help?

    Code (CSharp):
    1. public class RrAndroidBackButton : MonoBehaviour {
    2.  
    3.     public static RrAndroidBackButton instance;
    4.  
    5.     void Awake() {
    6.         if (null == instance) {
    7.             instance = this;
    8.             DontDestroyOnLoad(this.gameObject);
    9.         } else {
    10.             Destroy(gameObject);
    11.         }
    12.     }
    13.  
    14.     void FiexdUpdate () {
    15.         if (Application.platform == RuntimePlatform.Android){
    16.             if (Input.GetKey(KeyCode.Escape)) {
    17.                 Application.Quit();
    18.  
    19.                 System.Diagnostics.Process.GetCurrentProcess().Kill();
    20.  
    21.                 AndroidJavaObject activity = new AndroidJavaClass("com.unity3d.player.UnityPlayer")
    22.                         .GetStatic<AndroidJavaObject>("currentActivity");
    23.                 activity.Call<bool>("moveTaskToBack", true);
    24.             }
    25.         }
    26.     }
    27. }
     
  2. JuliusM

    JuliusM

    Unity Technologies

    Joined:
    Apr 17, 2013
    Posts:
    835
    You have a mistake in the method name. "FiexdUpdate" should be "FixedUpdate". Although just "Update" would be fine as well.
     
    Schumaker likes this.