Unity Life Cycle related to Mobile platform
— Android, Unity development — 1 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 = false3void OnApplicationPause(bool pause){4if(pause)5{6 //Switch to background7}8else9{10 //Switch to front11}12}
1//Application goes to background focus = false 2//Application goes to front focus = true3void OnApplicationFocus(bool focus){4 if(focus)5 {6 //when the application is in focus7 }8 else9 {10 //when the applicaiton is running on the background11 }12}
Different Usage
1//Start the App:2OnApplicationFocus, isFocus=True3
4//Quit the App:5OnApplicationQuit6
7//Get out by pressing home:8OnApplicationPause, isPause=True9OnApplicationFocus, isFocus=False10
11//Go in with home12OnApplicationPause, isPause=False13OnApplicationFocus, _isFocus=True14
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 background21OnApplicationQuit (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