Tuesday 21 July 2009

Multitasking for the iPhone: something simple

We all known that the iPhone/iPod has a much slower CPU than a 'standard' Mac or PC. So this means that the user experience can be a bit sluggish.
So when we have for example a time consuming task it comes in handy to use some multi-tasking capabilities built in , in Cocoa Touch.

However ,  I found out for myself a simpler and less difficult method of giving the user a good experience and still doing a lengthy task.
Of course this method only applies to tasks which takes 2-4 seconds , for longer tasks you'll need NSThread.

The trick I do is that I use an UIActivityIndicatorView somewhere on the screen so when a user 'sees' the screen he in fact see the spinning gear.
In the mean time the implementation of the time consuming task I do in the viewDidAppear: method.

So what happens is that the user sees a UI with something moving (the gear) so he knows that the application is actually doing something, and if it only takes 2 to 4 seconds he will never get frustrated.

I found this much easier than going to the route of NSThread with all the difficulties of locking of shared variables etc.

No comments:

Post a Comment