Android in Unity press the home button, press the return button, press the button to exit the program

tags: Unity

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/// <summary>
/// Function: return to home interface
/// </summary>

public class My_test10_returnHome : MonoBehaviour
{
    void Update()
    {
        if (Application.platform == RuntimePlatform.Android && (Input.GetKeyDown(KeyCode.Escape) || Input.GetKeyDown(KeyCode.Home)))
        {
            //Application.Quit();

            OnClick_applicationQuit();
        }
    }

    public void OnClick_applicationQuit()
    {
#if UNITY_EDITOR
        UnityEditor.EditorApplication.isPlaying = false;
#else
Application.Quit();
#endif
    }

}

 

Intelligent Recommendation

Capture Home button press

Override the onAttachedToWindow method in the Activity interface [img]http://dl.iteye.com/upload/attachment/573904/3dbd148c-7ddb-3344-96a8-3b710976169e.jpg[/img]...

Android press the home button or the back button to return to the desktop, again enter the program will restart the solution

Add the following code to the onCreate() method in the program entry interface.  ...

Android press the back button again to exit the application

Android uses a bit The following code is some of the tips and problems encountered in daily development, I hope to help you: 1.Implement and press again to exit the reminder The first Second...

android Press the back button to exit the application

Reproduced in: https: //www.cnblogs.com/luxiaofeng54/archive/2011/04/20/2022480.html...

Unity calls Android native activity, press Home button to return to be killed problem solved

Students who have done unity and Android native interaction should know that when we call the Android native activity in unity, press the Home button to return to the desktop, and then re-enter the un...

More Recommendation

Android is not MainActivity, press the home button, then open the program to enter MainActivity (unresolved)

In such a situation, when the launch mode of MainActivity is set to singleTask, press the home button on the non-MainActivity interface to return to the desktop. If you click the application icon to o...

Android press the Home button to re-enter the App

Android re-opens the app and enters the main activity after pressing the home button Problem description: When we write an App, there must be such a situation: the user has performed multi-level opera...

Android Press the HOME button to recreate the Activity problem

Problem Description: 1. When the APP starts page LauncherActivity startup mode is Singletask, jump to other pages secondactivity, at this time, click AppAP again after pressing the HOME button, first ...

Android distinguish button long press and short press

** Android distinguish button long press and short press ** Normally long press will always go onkeydown, so it is best to use onkeyup to distinguish when distinguishing; Note event.startTracking(); /...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top