开发者

Asynchronous Callback functions: Iphone Versus Android

On Callback

On Iphone

File A:

@proto开发者_JS百科col servicedelegate -(void)taskCompleted:(NSDcitionary*) dict; @end

-(void) performtask callback=@"taskCompleted:";

[(id)delegate performSelector:NSSelectorFromString(callback) withObject:data];

File B:

-(void) taskcompleted:(NSDictionary*)dict {

//don something when File A fisnihed the taskcompleted and have the data // this callback on File B will be awaken from File A's delegate function }

The question How does Android implement the above, File A waiting to getting the data, and nobody knows how long, but once finished, File B would awaken by the delegate callback function of taskcompleted.


There are a couple different ways:

  • Handlers
  • AsyncTask

I'm a fan of AsyncTask myself, but they require more boilerplate. Handlers can often be simpler.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜