When a game goes into background on iOS, what should I do to avoid getting stuck? - iphone

I am doing a game on iOS using starling AIR. It can running on iPhone and iPad. It contains a lot of animation and needs to connect to the server when playing.
The problem is, when the game enter background or the screen locked for a while, sometimes the game will stuck, sometimes it will restart, sometimes it will running normally.
I have read the AIR iOS – Background Behavior.
I know that when the application is suspended, os will handle memory optimization, it depends on the apps running foreground.
But what should I do when the game enter background ?
Let the game restart or run normally is fine, but avoiding stuck.
Thank you for all answers.

What you need to do is save your application state when your app is suspended, and restore it when its restored. There's a failry lengthy tutorial on Adobe Devnet showing how they recommend doing that.
Saving State in AIR Applications(Link)

"What to Do When Moving to the Background" and "Memory Usage for Background Apps" section of the documentation clearly explains this.

Related

iPhone OpenGL ES app killed on iPad when using "2x" button

Hey, I got kind of a weird issue here.
I have an iPhone-only OpenGL ES app which runs fine on all iPhone and iPod touch models supported.
When running on the iPad, it runs on an iPhone-sized window as expected, and pressing the "2x" button once scales up the window to twice the size, as expected, and the app continues to run without problems.
But if the user taps the "2x" button 3 or 4 times quickly, the app is killed with the Program received signal: "0" message (which, from what I understand, means the OS killed my app for using too much memory, is that right?)
What I really do not understand is what in my app could possibly be using up more memory when the iPad scales the window up and down? As far as I know there's not even any way for my app to tell if and when the iPad is doing that. I don't know if the fact I'm using OpenGL ES is related or not, but that issue doesn't happen on any of the Cocoa Touch apps I have - though it also doesn't happen on the other two OpenGL ES apps I have. And this app does use more memory than any of the other ones.
Anyone ever had or even heard of this problem? Googling gave me nothing.
Since no one has posted with a direct answer (your situation might be a little vague), I have a suggestion for how to move forward and gather more information on what might be causing your problem.
Check out the Instruments in Xcode which can identify memory leaks:
Instruments User Guide
Or for an even friendlier introduction, here's a video that address performance issues, including memory leaks (and how to find them). iOS Performance Optimization Video
Just adding this so there's some kind of an answer here...
I never figured out what the hell was going on with the 2x button.
The way I fixed it back then was to optimize memory usage as much as I could, lazy-load all that I could and unload again when not in use.
Weird that it never complains about memory when running on any of the supported iPhone or iPod touch models, even the older ones, but it got killed on the iPad ONLY when pressing the 2x button repeatedly and quickly... I guess that's always gonna be a mystery to me.

iphone:Multitasking in iphone not possible

Does iphone support multitasking for third party applications.Canone explain me how.
Assuming your device is newer than an iPhone 3G (or 1st gen iPod Touch), then yes, your application may run in the background. Note that even iOS4 doesn't allow multitasking on the older devices. What happens in iOS4 and above is that when you press the home button from an application, it switches the current app to the background - however, it is still running.
When working with games this means you have to use your application delegate to pause your game when the application is sent to the background, and (optionally) resume it when it returns, or present a "pause menu". It should also switch to a low/idle rendering loop (4FPS or similar), however, extra care has to be taken with iPad apps, which do not allow OpenGL rendering in an application that is currently in the background (in my experience). For these cases you have to completely disable the OpenGL render loop. These steps will prevent your application using unnecessary processing power while in the background.
You can see what's currently running in the background by double-tapping the home button on your device. The icons for all the apps will appear in a sliding list at the bottom of the screen. You can press and hold them to bring up the little X's allowing you to terminate the processes.

GUI is stuck with uibackgroundmodes= voip, audio

I have tabbar-based application. When I put in my plist UIBackgroundModes (my application is supposed to support voip), the GUI doesn't load. It sucks on Splash screen and doesn't load the first tab view. When i remove the UIBackgroundModes property from info.plist, it works fine. More than that, pressing the home button when it stuck does nothing. Did somebody encountered a similar problem? (The problem exists on simulator)
Thanks,
Nava
It appears, that the problem happens on Simulator only, it works on the device... So the solution (temporary one) is not to put UIBackgroundModes into info.plist for simulator version.
You are responsible for loading/unloading the interface when going in and out of the background mode. You'll also need to update the interface accordingly when coming out of background.
iOS helps a bit by taking a screenshot before putting the app in background and displaying it when getting the app to foreground (a bit like Default.png when starting the app) and also some UIImage caching.
It might be worth sharing some code.
Supporting Background State Transitions
Supporting the background state transition is part of the fundamental architecture for applications in iOS 4 and later. Although technically the only thing you have to do to support this capability is link against iOS 4 and later, properly supporting it requires some additional work. Specifically, your application delegate should implement the following methods and implement appropriate behaviors in each of them:
application:didFinishLaunchingWithOptions:
applicationDidBecomeActive:
applicationWillResignActive:
applicationDidEnterBackground:
applicationWillEnterForeground:
applicationWillTerminate:
Being a Responsible, Multitasking-Aware Application
Applications that run in the background are more limited in what they can do than a foreground application. And even if your application does not run in the background, there are are certain guidelines you should follow when implementing your application.
Do not make any OpenGL ES calls from your code. You must not create an EAGLContext object or issue any OpenGL ES drawing commands of any kind. Using these calls will cause your application to be terminated immediately.
[...]
iOS Application Programming Guide
I see this bug as well. It's very annoying. It's as if the app is stuck in the simulator and won't keep going. When this happens, I know how to "unstick" it.
In the simulator I just go to menu Hardware > Lock and then unlock the phone again. Now I stop the debugger and start the app again. This seems to kick it back to life.
Fortunately this bug doesn't happen on a real phone, only in the simulator.

How to run my app even after iPhone screen locks?

I want my app (LaunchDaemon) to keep running even if user locks the iPhone. My LaunchDaemon simply check a file and if some condition is true, it displays an Alert to the User. Its working great when iPhone is on Home Screen, but it is not working when user Locks the Screen.
I want something Similar to Alarm app of iPhone which will show an Alert even if the iPhone screen is Locked.
Any suggestions on how to do this? BTW i am developing for JB iPhone.
OS powers down the device and suspends your app after about 30 seconds after screen is locked. However,
if your app is playing a sound OS will not do that. Hence what you need to do is play a silent sound in a loop.
Alright i have solved this problem too.
Here is a very good tutorial on how to prevent deep sleep of iPhone.
Prevent iPhone Deep Sleep
It took me quite sometime to made this work, as NSRunLoop was not running for me automatically.
Hope this will help someone else also.
Best of Luck !!!

iPod app stops responding after iPod returns from standby mode

The GUI of my application stops responding after the iPod has been in standby mode. The application I have made is based on the "Utility application" template from the wizard in xcode - but the original application still works after the iPod returns from standby.
My application plays music (AudioUnit) and when the iPod enters standby the music stops but when the iPod leaves standby mode the music starts playing again but as mentioned the GUI does not respond to touches anymore. All I can do is to shut it down.
I have read about this problem here:
What happens to an iPhone app when iPhone goes into stand-by mode?
but that did not help me enough to solve the problem.
Sounds like your Audio Unit has been stopped.
If your GUI relies on the AU's progress then that would explain the problem.
Check your AU's state in applicationDidBecomeActive.
I didn't think standby mode stopped AUs, I thought only audio interruptions
did that. Anyway, you should probably look at AudioSessions as well, as you'll
find that phone calls, alarms, SMSs and ipod music will also stop your Audio Unit.
Good luck.
Actually, I've been running into this problem on the iPod application itself, in just general daily use. That is, if you are using the 3.0 firmware OS, then this is most likely a bug in the iPhone. I guess you can relax, and know that it's probably not your own code that is causing the problem. I'd file a radar ticket with Apple if you haven't already so that they can address it in the next bug fix release.
It all happens just because I have an UISlider in an UIToolbar. If I remove the UISlider from my GUI it still responds after waking up from standby/sleep mode.
Can someone explain me why that causes this problem (is it a bug in Apple's code)?
The solution is here:
http://www.iphonedevsdk.com/forum/iphone-sdk-development/4558-app-crashing-upon-quit.html
Simply don't put a slider in a toolbar. Make a work around so it looks like the slider is in the toolbar instead. It is a bug in Apple's code.