- Home /
How to get some background process time after OnApplicationPause
Hello,
Is there a way in Unity (I'm coding in C#), to get some process time to run a task in background when the app is put to background? I'm looking for an equivalent of "beginBackgroundTaskWithExpirationHandler" function from iOS library, which if possible would work on both iOS and Android. Something to allow me to do the same as that:
- (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
UIApplication *app = [UIApplication sharedApplication];
bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
[app endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}];
myFunctionThatCouldBeLong();
}
Answer by dannyskim · Oct 15, 2012 at 07:05 PM
Not sure if this thread is still relevant, but I had it in my bookmarks for reference.
http://forum.unity3d.com/threads/110512-continue-running-app-in-background-for-audio-generation-(iOS)
If you do decide to use this method, remember that when you build your project from Unity3D to XCode and you hit 'Replace' instead of 'Append,' all your changes to the AppController.mm file will be deleted. To work around this, you can either save a copy locally and recopy it whenever you need, or write a Post Process script to get around that issue.
It seems to be very complicated regarding what I'm looking for; in fact, I should not have called my function "myFunctionThatCouldBeLong" because it only takes a few second. I only need a little delay for my function to end. And I already have the possibility to do this in XCode with the code I put in my original question, I am more looking for a Unity way to do this, so it also works on Android, but maybe that doesn't exist.
Your answer
![](https://koobas.hobune.stream/wayback/20220613082352im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Keep unity running when minimized on iOS and Android 2 Answers
Run a script in background when the app is open or closed 5 Answers
Is there a Tutorial on Running Android, iOS in background? 1 Answer
Background Networking Activity and Unity Run Loop 0 Answers
Strange graphic bugs with Vuforia on Android and iOS 0 Answers