开发者

What's Android Equivalent of iOS's Post Notification and Delegate function?

I find the Post notification and delegate function are very useful in iOS. Once I finish a task I can notify another piece of code to do something. I am sending out notices for others to do the work.

Post Notification is when you sending notice right away, whereas delegate sometime down the line it will send a notice.

In Android I know there's event Listener, but that's only passive listening. What about me actively sending notices? Does Android have th开发者_开发问答at equivalent?


Handler which can be fired right away or with postDelay() you can fire them later


You could either use a Handler to get notified from a running Thread or the AsyncTask which does run some code and after it's finished it notifies the UI Thread.


You are probably looking for a way to thread your application? Where there are other "worker" threads that do long computations (or do buffered IO stuff). The way you would do this is by creating an AsyncTask. Within an AsyncTask, there is a "doInBackground" method that seems to be what "delegate" is in your question. "onPostExecute" will handle whatever's returned in "doInBackground". More in the AsyncTask documentation.

Another option is to simply use a Handler and use postDelay() for later executions:

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜