Unity close application android

MonoBehaviour.OnApplicationQuit()

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Submission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Description

Sent to all GameObjects before the application quits.

In the Editor, Unity calls this message when playmode is stopped.

Note: iOS applications are usually suspended and do not quit. For iOS builds, enable the » Exit on Suspend » property in Player Settings to make the application quit and not suspend, otherwise you might not see this call. If you do not enable the » Exit on Suspend » property then you will see calls to OnApplicationPause instead.

On Windows Store Apps and Windows Phone 8.1 there is no application quit event. Use the OnApplicationFocus event when focusStatus equals false .
On WebGL it is not possible to implement OnApplicationQuit because of the way browser tabs close. For a workaround, see the Unity User Manual documentation on Interacting with browser scripting in WebGL.

Warning: If the user suspends your application on a mobile platform, the operating system can quit the application to free up resources. In this case, depending on the operating system, Unity might be unable to call this method. On mobile platforms, it is best practice to not rely on this method to save the state of your application. Instead, consider every loss of application focus as the exit of the application and use MonoBehaviour.OnApplicationFocus to save any data.

Is something described here not working as you expect it to? It might be a Known Issue. Please check with the Issue Tracker at issuetracker.unity3d.com.

Copyright ©2021 Unity Technologies. Publication Date: 2021-11-26.

Источник

Application

class in UnityEngine

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Submission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Description

Access to application run-time data.

This class contains static methods for looking up information about and controlling the run-time data.

Static Properties

absoluteURL The URL of the document. For WebGL, this a web URL. For Android, iOS, or Universal Windows Platform (UWP) this is a deep link URL. (Read Only)
backgroundLoadingPriority Priority of background loading thread.
buildGUID Returns a GUID for this build (Read Only).
cloudProjectId A unique cloud project identifier. It is unique for every project (Read Only).
companyName Return application company name (Read Only).
consoleLogPath Returns the path to the console log file, or an empty string if the current platform does not support log files.
dataPath Contains the path to the game data folder on the target device (Read Only).
genuine Returns false if application is altered in any way after it was built.
genuineCheckAvailable Returns true if application integrity can be confirmed.
identifier Returns application identifier at runtime. On Apple platforms this is the ‘bundleIdentifier’ saved in the info.plist file, on Android it’s the ‘package’ from the AndroidManifest.xml.
installerName Returns the name of the store or package that installed the application (Read Only).
installMode Returns application install mode (Read Only).
internetReachability Returns the type of Internet reachability currently possible on the device.
isBatchMode Returns true when Unity is launched with the -batchmode flag from the command line (Read Only).
isConsolePlatform Is the current Runtime platform a known console platform.
isEditor Are we running inside the Unity editor? (Read Only)
isFocused Whether the player currently has focus. Read-only.
isMobilePlatform Is the current Runtime platform a known mobile platform.
isPlaying Returns true when called in any kind of built Player, or when called in the Editor in Play Mode (Read Only).
persistentDataPath (Read Only) Contains the path to a persistent data directory.
platform Returns the platform the game is running on (Read Only).
productName Returns application product name (Read Only).
runInBackground Should the player be running when the application is in the background?
sandboxType Returns application running in sandbox (Read Only).
streamingAssetsPath The path to the StreamingAssets folder (Read Only).
systemLanguage The language the user’s operating system is running in.
targetFrameRate Instructs the game to try to render at a specified frame rate.
temporaryCachePath Contains the path to a temporary data / cache directory (Read Only).
unityVersion The version of the Unity runtime used to play the content.
version Returns application version number (Read Only).
Читайте также:  Si cam cms андроид

Static Methods

CanStreamedLevelBeLoaded Can the streamed level be loaded?
GetBuildTags Returns an array of feature tags in use for this build.
GetStackTraceLogType Get stack trace logging options. The default value is StackTraceLogType.ScriptOnly.
HasProLicense Is Unity activated with the Pro license?
HasUserAuthorization Check if the user has authorized use of the webcam or microphone in the Web Player.
IsPlaying Returns true if the given object is part of the playing world either in any kind of built Player or in Play Mode.
OpenURL Opens the URL specified, subject to the permissions and limitations of your app’s current platform and environment. This is handled in different ways depending on the nature of the URL, and with different security restrictions, depending on the runtime platform.
Quit Quits the player application.
RequestAdvertisingIdentifierAsync Request advertising ID for iOS and Windows Store.
RequestUserAuthorization Request authorization to use the webcam or microphone on iOS.
SetBuildTags Set an array of feature tags for this build.
SetStackTraceLogType Set stack trace logging options. The default value is StackTraceLogType.ScriptOnly.
Unload Unloads the Unity Player.

Events

deepLinkActivated This event is raised when an application running on Android, iOS, or the Universal Windows Platform (UWP) is activated using a deep link URL.
focusChanged Defines the delegate to use to register for events in which the focus gained or lost.
logMessageReceived Event that is fired if a log message is received.
logMessageReceivedThreaded Event that is fired if a log message is received.
lowMemory This event occurs when your app receives a low-memory notification from the device it is running on. This only occurs when your app is running in the foreground. You can release non-critical assets from memory (such as, textures or audio clips) in response to this in order to avoid the app being terminated. You can also load smaller versions of such assets. Furthermore, you should serialize any transient data to permanent storage to avoid data loss if the app is terminated.This event is supported on iOS, Android, and Universal Windows Platform (UWP).This event corresponds to the following callbacks on the different platforms:iOS: [UIApplicationDelegate applicationDidReceiveMemoryWarning]Android: onLowMemory() and onTrimMemory(level == TRIM_MEMORY_RUNNING_CRITICAL)UWP: MemoryManager.AppMemoryUsageIncreased (AppMemoryUsageLevel == OverLimit)Note: For UWP, this event will not occur on Desktop and only works on memory constrained devices, such as HoloLens and Xbox One. The OverLimit threshold specified by the OS in this case is so high it is not reasonably possible to reach it and trigger the event.Here is an example of handling the callback:
onBeforeRender Delegate method used to register for «Just Before Render» input updates for VR devices.
quitting Unity raises this event when the player application is qutting.
unloading Unity raises this event when Player is unloading.
wantsToQuit Unity raises this event when the player application wants to quit.
Читайте также:  Retrofit 2 android примеры post

Delegates

AdvertisingIdentifierCallback Delegate method for fetching advertising ID.
LogCallback Use this delegate type with Application.logMessageReceived or Application.logMessageReceivedThreaded to monitor what gets logged.
LowMemoryCallback This is the delegate function when a mobile device notifies of low memory.

Is something described here not working as you expect it to? It might be a Known Issue. Please check with the Issue Tracker at issuetracker.unity3d.com.

Copyright ©2021 Unity Technologies. Publication Date: 2021-11-26.

Источник

Application.Quit

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Submission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Declaration

Parameters

exitCode An optional exit code to return when the player application terminates on Windows, Mac and Linux. Defaults to 0.

Description

Quits the player application.

Shut down the running application. The Application.Quit call is ignored in the Editor.

If you want to use Application.Quit when running Unity inside another application, see the UnityasaLibrary-Android Unity as a Library Manual page for more information.

Note: In most cases termination of application under iOS should be left at the user’s discretion. Calling this method in iOS player might appear to the user that the application has crashed. For more information, see Apple Technical Page qa1561.

Is something described here not working as you expect it to? It might be a Known Issue. Please check with the Issue Tracker at issuetracker.unity3d.com.

Copyright ©2021 Unity Technologies. Publication Date: 2021-11-26.

Источник

Integrating Unity into Android applications

This page describes how to integrate the Unity Runtime Library into Android applications using the Unity as a Library feature.

You can use this feature to include Unity-powered features, such as 3D/2D Real-Time Rendering The process of drawing graphics to the screen (or to a render texture). By default, the main camera in Unity renders its view to the screen. More info
See in Glossary , AR Augmented Reality (AR) uses computer graphics or video composited on top of a live video feed to augment the view and create interaction with real and virtual objects.
See in Glossary Experience, 3D model interaction, or 2D mini-games, into your application. The Unity Runtime Library exposes controls to manage when and how to load, activate, and unload content within the application.

Читайте также:  Российские платежные системы для андроид

Important: If you upgrade your project to Unity 2019.4 or above, the introduction of Unity as a Library might require you to adapt native and managed plug-ins A set of code created outside of Unity that creates functionality in Unity. There are two kinds of plug-ins you can use in Unity: Managed plug-ins (managed .NET assemblies created with tools like Visual Studio) and Native plug-ins (platform-specific native code libraries). More info
See in Glossary to work properly for Android. Plug-ins that make changes to Gradle An Android build system that automates several build processes. This automation means that many common build errors are less likely to occur. More info
See in Glossary manifests need to use the the Gradle changes outlined in Using Unity as a library in native iOS/Android apps.

How it works

You don’t need to do anything different when you build your Gradle project from Unity.

Every Android Gradle project that Unity generates has the following structure:

  • A library part in the unityLibrary module that you can integrate into any other Gradle project. This contains the Unity runtime and Player data.
  • A thin launcher part in the launcher module that contains the application name and its icons. This is a simple Android application that launches Unity. You can replace this module with your own application.

To integrate Unity into another Android Gradle project, you must include the unityLibrary module of the generated Android Gradle project in your Android Unity Project through the settings.gradle file.

This repository contains example Projects and plug-ins that demonstrate how to integrate Unity into an Android app, along with further documentation.

To control a Player, relay an Intent to launch Unity activity and extend it if needed. For more information, see Android developer documentation on Intents and Intent Filters. You can also use the UnityPlayer Java API.

IUnityPlayerLifecycleEvents

IUnityPlayerLifecycleEvents provides a way to interact with two important lifecycle events of the Unity Player:

  • Unload — The application calls IUnityPlayerLifecycleEvents.onUnityPlayerUnloaded when Application.Unload or UnityPlayer.unload() unloads the Unity Player. This puts the Unity Player in a paused state where it unloads all Scenes A Scene contains the environments and menus of your game. Think of each unique Scene file as a unique level. In each Scene, you place your environments, obstacles, and decorations, essentially designing and building your game in pieces. More info
    See in Glossary , but keeps everything else loaded in the memory.
  • Quit — The application calls IUnityPlayerLifecycleEvents.onUnityPlayerQuitted when the Unity Player quits. The process that was running Unity ends after this call.

You can pass an instance of IUnityPlayerLifecycleEvents to the UnityPlayer constructor, or to override methods in subclasses of UnityPlayer and UnityPlayerActivity .

Limitations

Unity doesn’t control the runtime lifecycle, so Unity as a Library might not work for all possible use cases. Known limitations include:

  • Unity as a Library only supports full-screen rendering, and doesn’t support rendering on part of the screen.
  • You can’t load or integrate more than one instance of the Unity runtime.
  • You might need to adapt third-party plug-ins (both native and managed) to work with the Unity runtime.
  • Unity as a Library for Android added in 2019.3. NewIn20193

Источник

Оцените статью