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 are updating our Terms of Service for all Unity subscription plans, effective October 13, 2022, to create a more streamlined, user-friendly set of terms. Please review them here: unity.com/legal/terms-of-service.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice
  4. Join us on Thursday, September 29, for a day with Unity's SRP teams here on the forum or on Reddit, and discuss topics around URP, HDRP, and the Scriptable Render Pipeline in general.
    Dismiss Notice

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:
    821
    You have a mistake in the method name. "FiexdUpdate" should be "FixedUpdate". Although just "Update" would be fine as well.
     
    Schumaker likes this.
unityunity