- Home /
Does OnApplicationPause actually work?
There are lots of answers suggesting using OnApplicationPause for doing stuff when the application goes out of focus (for instance, when the Home button on the iPhone is pushed).
We don't see that this function is called.
Does this in fact work, or do you need magic to make it so? If not, why does so many answers suggest it, and how do those answer get accepted?
Edit: And why is none of this in the documentation, Unity guys?
Edit: We need a solution for iPhone (and Android).
More info: The OnApplicationPause does get called for PC (with RunInBackground switched off), and on iPhone when we put it in the class that directly extends from Monobehaviour (in our system, called DebuggableManobehaviour), but not in any classes that extend from DebuggableManobehaviour (which is all the game classes in our project).
TIA
ht
Hi Herman,
Did you fix this issue??? I have the same problem, my application still running in background when is interrupt with lock or home button.
I'll really apreciate if you can tell me what you did to solve this problem and pause calling OnApplicationPause method.
Thanks.
Have you made OnApplicationPause() virtual in Debuggable$$anonymous$$anobehaviour and used the override keyword when overriding it in the subclass?
Answer by jonas-echterhoff · Jan 19, 2011 at 02:26 PM
If the player is paused, OnApplicationPause should be called. If it isn't, that's a bug, you should file it. Is your player actually pausing? Maybe you have the run in Background checkbox enabled?
Thanks, Jonas. I only see the option for Windows and Web player. Is it at all available for iPhone? We can see that the UnityPause (AppController.mm) function is called in from the Unity-generated XCode, but for some reason the OnApplicationPause does not reach our application.
Jonas, we have narrowed the issue down (see my updated question), so you are right, this is a nasty little bug, at least one with a workaround, however annoying it is. We will file a bug report. Thanks for the "run in background" info (it would be handy if that could be in the docs under the OnApplicationPaused description...)
Answer by shinriyo_twitter · Feb 08, 2013 at 09:13 AM
Edit: We need a solution for iPhone (and Android).
iPhone can work. but iPod doesn't work well.. Android doesn't support. you must create plugin
Answer by nicloay · May 26, 2015 at 01:24 PM
It works on iOs, but doesn't on android. I have heavy task finished before app goes to bg(take screenshot and store to the local drive) and i see that this job is paused when app goes to background and finished only when you come back. so if you close the app while it is in background it won't be finished.
upd1: Actualy method called on android as well, the problem is that it doesn't wait until the method is done, even if you make it as coroutine. and it's a problem for me. I need to make serialization, and the method complete only when you focus your app back.