iPhone Crashes If Current Window is Closed Too Quickly
I have an iPhone app with a window that fires a custom event that kicks off a DB query, collects data from the result set, iterates over the collected data and creates a view from the data, adding it to the current window. The problem I'm running into is that the app will crash if the window is closed before the looping over the collected data is completed.
I'm logging progress during the loop, so I know the crash isn't occurring during the DB interaction. I've tried adding event listeners to the current window's close and blur events to "short circuit" the loop, but they don't seem to fire in time.
I'm guessing this might be a thread safety problem? Does anyone have any ideas? Thanks.
3 Answers
-
Accepted Answer
Without knowing what your code looks like, I'll suggest workarounds that might be possible:
- listen to the window
close
event - you can add a listener for this event so you can update a state variable which will indicate that the window has been closed, and avoid trying to add items to it. - fetch the db records before opening the window
- listen to the window
-
I guess you would have to find a way to slow down the window close event. Maybe you can set a global flag to tell the DB code to abort the loop.
Then, have the db loop set another global flag indicating that it's done. Only then would you go ahead with the window close.
In the window close event you could maybe use the javascript setTimeout() function to keep waiting for a few hundred ms?
-
I hava the same problem?how do you disable the backbutton on iPhone?I can't find any idea about this~~~