When appropriate simply means that it will, literally, queue up the messages. A queue by definition is a collection of items that get handled in a FIFO order (First In, First Out).
The Handler is really nice because you can use it to still send messages to your UI (and therefore, update your UI without much additional work). I have a blog post here about Android Handlers... http://www.sep.com/mcterry/2011/08/05/android-handler-in-a-nutshell/ Ideally, you would display a progress bar/dialog, and do your work in the Handler. You can continue to communicate with the progress bar/dialog, and never blog the UI thread. If you write your own Callback interface, you'll have to manage all of the concurrency and timing issues yourself, as well as, handle all of the UI messages/inputs. For example, what happens if the user presses the "back" button while your callback is being executed? Can you recover from that callback? What about orientation changes, does that interrupt your callback since it was likely called from the UI Thread which will get updated as part of your Activity's lifecycle? I hope this helps! -Matt www.sep.com/mcterry On Thursday, March 22, 2012 7:33:12 AM UTC-4, dakishin wrote: > > Hi all, > > could you explain me differences between android.os.Handler class and > my own CallBack class. > > Usecase of Handler: > > void do(Handler handler){ > new Thread(){ > void run(){ > > Message message=handler.obtainMessage(); > message.obj=new Result(); > handler.sendMessage(message); > } > > }.start(); > } > > Usecase of my custom CallBack class > > public interface CallBack{ > void onResult(Result result); > } > > > void do(CallBack callback){ > new Thread(){ > void run(){ > callBack.onResult(new Result()); > } > > }.start(); > } > > JavaDoc says: "Message will then be scheduled in the Handler's message > queue and processed when APPROPRIATE". What does it mean? > > > -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

