Skip to content
BigBro222's Blog
LinkedInGitHub

Unity Life Cycle related to Mobile platform

Android, Unity development1 min read

Note that all these note, is also avaliable on Android-based VR devices. Be used for event tracking service

1//Application goes to background pause = true
2//Application goes to front pause = false
3void OnApplicationPause(bool pause){
4if(pause)
5{
6 //Switch to background
7}
8else
9{
10 //Switch to front
11}
12}
1//Application goes to background focus = false
2//Application goes to front focus = true
3void OnApplicationFocus(bool focus){
4 if(focus)
5 {
6 //when the application is in focus
7 }
8 else
9 {
10 //when the applicaiton is running on the background
11 }
12}

Different Usage

1//Start the App:
2OnApplicationFocus, isFocus=True
3
4//Quit the App:
5OnApplicationQuit
6
7//Get out by pressing home:
8OnApplicationPause, isPause=True
9OnApplicationFocus, isFocus=False
10
11//Go in with home
12OnApplicationPause, isPause=False
13OnApplicationFocus, _isFocus=True
14
15//Kill the process:
16
17////Double press Home,and Kill:
18OnApplicationQuit (IOS called,android not called)
19
20////Get out of home first and kill from background
21OnApplicationQuit (IOS and Android not called)
22
23////OnApplicationQuit will always be called when application.quit is called

Reference

https://blog.csdn.net/shuangkui5355/article/details/80358079

https://dev.to/kento/unity-a-solution-if-you-cant-receive-the-event-that-finishes-an-app-on-mobile-4n2d

© 2023 by BigBro222's Blog. All rights reserved.