Message has several fields for switching the logic on the receiving end: int what Object obj int arg1 int arg2
http://developer.android.com/reference/android/os/Message.html So you could do something like: void handleMessage(Message msg) { final int what = msg.what; switch (what) { ... } } Or even: void handleMessage(Message msg) { Runnable r = (Runnable) msg.obj; r.run(); } ( or same with your own interface / base class ) -- Kostya 30 ноября 2011 г. 16:32 пользователь John Goche <[email protected]>написал: > > Thank you TreKing for your advice, > > But then in my handleMessage I would have to check with > > if (inst instance of Foo) > inst.foocallback(); > else if (inst instanceof Bar) > inst.barcallback(); > else if (...) > > or is there a neater solution, perhaps using polymorphism or a design > pattern of some sort > so that my handleMessage does not quickly turn into a mess? > > Thanks, > > John Goche > > > > On Tue, Nov 29, 2011 at 11:02 PM, TreKing <[email protected]> wrote: > >> On Tue, Nov 29, 2011 at 3:46 PM, John Goche >> <[email protected]>wrote: >> >>> The number of sprites is indefinite (could vary in number) but each >>> needs to manage itself individually. On top of this the world has its >>> own handler to manage updates to itself. >>> >> >> You don't need separate handlers, you can pass the instance of the object >> that is being updated in the handler message, then use one single handler >> for the main thread. >> >> >> ------------------------------------------------------------------------------------------------- >> TreKing <http://sites.google.com/site/rezmobileapps/treking> - Chicago >> transit tracking app for Android-powered devices >> >> -- >> 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 > > > -- > 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 > -- 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

